does anyone know any easy way of reading in a file line by line.
im assuming i need to use ifstream
then just do while (!file.eof()) getline(file, string);
i need to read each string into a switch statement and then extract 3 values: vertex.x vertex.y vertex.z for each string read in depending on the case statements. can anyone shed some light? ill supply code if it helps

>while (!file.eof())
While this can be made to work, it requires unnecessary redundancy or an uncommon looping idiom. Anything else is incorrect because eof() only returns true after an attempt to read from the stream has failed, so the loop will iterate twice for the last record in the file. That's almost always a subtle and grievous error.

The best way to take input with a loop is to use the return value of your input function as the loop condition:

while ( getline ( file, string ) ) {
  // Stuff
}

Because getline returns an istream&, and istream has a conversion to void* for conditional tests, you can use the getline call as a loop condition and it will "just work".

>i need to read each string into a switch statement
You'll have to be more specific, strings can't be used as the condition for a switch statement. Cases must be integral.

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.