Search code examples
c++stringstream

C++ stringstreams skipping a character


I have a file which the first line reads ">FileName.txt". My goal is to read this line, and save "FileName.txt" to a variable called name. So I have:

ifstream file;

/* File opening stuff */

string line, name;

getline(file,line);

stringstream converter(line);

converter >> name;

This accomplishes saving ">FileName.txt" to the variable name, but I need to remove the '>' character. I am not sure if I should do that after this point, or if there is a way to skip over it entirely using the stringstream.


Solution

  • You can skip over it with the stream fairly easily:

    char ch;
    converter >> ch; // skip initial >
    converter >> name; // now read the name