-2

I have a text file with the following layout:

step=fixed step start=100 step=1

32

112

step=fixed step start =211 step=1

11

34

and so on I need to extract the numbers 100 and 211 respectively i.e. the start values as integers in my code and carry out some operations.

mwerschy
  • 1,698
  • 1
  • 15
  • 26
csdota
  • 1

1 Answers1

0

getchar and use space as delimiter. Or use scanf and formatted string. (but it still needs some spaces between words and numbers.)

Example:
scanf("%s %s %s %s %d",variables..);
scanf("%d",var);
scanf("%d",var1);

since you know format its quite easy. If it is from file use fscanf.

Dejan
  • 3,046
  • 3
  • 28
  • 43
  • 1
    Buffer overrun issues. Use `std::string` and `std::getline` instead. Also use `std::istringstream` for extracting from the `std::string`. – Thomas Matthews May 26 '13 at 18:32
  • Maybe a man is using something low level. If he has iostream.h he can use those. Those are even easer that you mentioned. – Dejan May 26 '13 at 18:36
  • For the OP, there is no need to use low level I/O. The OP should consider correctness and safety first. The C++ streams may be slower, but they are safer. If the file is huge or is the bottleneck, using block reading and parsing in memory would be the preferred method. – Thomas Matthews May 26 '13 at 18:44