Erasing front of string

I need to read in from a file that looks like:

1: Name
12: Name
123: Name
.
.
.
12343: --End of Data --

I need to output the Names without the numbers and colon in front.

I have tried substr but because the numbers get larger that doesn't work. It also is in a loop and I need it to stop when it finds --End of Data--. The code works properly except it prints the numbers and colon and I can't compare the line with --End of Data-- to restart the loop because the numbers change in front. If I manually put the numbers and colon in front, it works properly. So I am wondering if there is a way to erase the beginning not knowing how many numbers are before the Name? Thanks
Last edited on
Have you considered a stringstream?

1
2
3
4
5
6
string test("1:Name");
stringstream fin(test);
string garbage;
string name;
getline(fin, garbage, ':');
getline(fin, name);



You can get the position of : with string::find. Then you can use the position with the string::substr.


Edit:
Since you do read a file, you can use jlb's pair of getlines directly on the ifstream.
Or, ignore up to ... see http://www.cplusplus.com/reference/istream/istream/ignore/
Last edited on
Thanks guys. I knew it was something I was thinking too hard about. I added the getline with garbage and it works.
Topic archived. No new replies allowed.