Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 639
zZShort_CircuitZz Avatar asked May 18 '26 04:05

zZShort_CircuitZz


1 Answers

You can skip over it with the stream fairly easily:

char ch;
converter >> ch; // skip initial >
converter >> name; // now read the name
like image 127
Jonathan Potter Avatar answered May 20 '26 18:05

Jonathan Potter