Search code examples
c++streamistringstream

How to use IStringStream to read from a file?


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


Solution

  • #include <fstream>
    
    std::ifstream file("filename.txt");
    
    StuffType stuff;
    while(file >> stuff)
    {
        // If you are here you have successfully read stuff.
    }