onkar wrote:
I am in a situation wherein I want to process input line by line .
Each line contians numbers.
sample input :
1 2 3 4 5
5 6 7
1
2 3 4 56 7 8
0
my program must take 1 2 3 4 5 first -process it -5 6 7 -process
it and likewise. How can i do it without considering each line as a
string and seperating out numbers ? Can I directly use some kind of
loop ? and how is the loop going to terminate ?
I recently had to do something like this. I decided to treat the input file
as a set of logical records, rather than as a set of lines. A record can
span multiple lines. Each record is terminated by a semicolon.
I have a loop that uses the >operator to read tokens into a string
variable (called Token!). Each token string is then pushed into a list of
strings (list<std:stringfor further processing. A record is complete when
I find a token that is (or ends with) a semicolon.
The need for a semicolon terminator is necessary to give me the flexibility
to have records spanning multiple lines.
If you don't need this flexibility then the approach posted by juha Nieminem
looks sensible to me.
Chris Gordon-Smith
www.simsoup.info