3

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.

pezy
  • 1,022
  • 2
  • 8
  • 27

2 Answers2

5

You can skip over it with the stream fairly easily:

char ch;
converter >> ch; // skip initial >
converter >> name; // now read the name
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
2

You can skip over it with the function ignore, add follow statement after stringstream converter(line); only need one line.

converter.ignore(line.length(), '>');
pezy
  • 1,022
  • 2
  • 8
  • 27