tags:

views:

85

answers:

2

Hi all

I have a text file like below

2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
200 2
1 5
5 1 2 3 4 5
1 0
0 0

I want to read file line by line, and read the umbers from each line. I know how to use the stream to read a fixed field line, but what about the non-fixed line?

Best Regards,

+1  A: 
adf88
+8  A: 

Use a stringstream. In outline:

string line;
while( getline( cin, line ) ) {  // read each line:
   istringstream is( line );
   int n;
   while( is >> n ) {   // read each number in line
       // do something with each number:
   }
}
anon