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

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
}

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

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

since you know there are 4 numbers on a row

int a,b,c,d;

while( in >> a >> b >>c >>d )
{
  // blabla
}

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

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";
}

wow thanks a whole lot. now that i know what to do it seems so simple. thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.