0

Hey guys. Ive been working with fstream for about 2 hours and i give up. My problem is I have a text file with an unknown number of rows. Each row has a known number of items. i cant figure out how to read the elements in each row. after that i know i can finish what i have to do but its just the row by row thats killin me. Any help would be appreciated. Thanks

2
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by Barefootsanders
0

post one of the rows so we can see what kind of items it has. Generally, if they are all strings (or words). Assuming the name of the stream is in

std::string word;
while( in >> word )
{
   // blabla
}
0

sorry. each row has numbers in it. its formated like this:

3 53342 6343 1232
4643 3213 64 3
2 6 3 1

0

how would you go to the next row after you do what you have to do with the first set of numbers?

0

that loop will go through all the rows in the file. When end-of-file is reached the loop will stop. To verify that for yourself you can simply print the values on the screen

while( in >> a >> b >>c >>d )
{
    cout << a << " " << b << " " << c << " " << d << "\n";
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.