Reputation: 477
I need to read in an expression from a file using a string stream and convert the expression to into another form. But I am having trouble figuring out how to read lines from the file using the Istringstream. Can anyone help me with the #includes and syntax for this? Thanks
Upvotes: 0
Views: 1343
Reputation: 6858
As an addition to the answer of Dave above: to read one line from a file, you can use the following code:
char buf[256];
file.getline(buf,256);
The character string buf then contains the line of text in the file.
Upvotes: 1
Reputation: 28168
#include <fstream>
std::ifstream file("filename.txt");
StuffType stuff;
while(file >> stuff)
{
// If you are here you have successfully read stuff.
}
Upvotes: 1