How to use a string as a delimiter using getline function?

How do I use a string in place of a character in the function getline?

For example,

1
2
	getline(infile,lines,'}');
    


This works fine, but I want the delimiter of } to be "};", but I can't do this as it only takes in characters, not strings.

I want:

 
	getline(infile,lines,"};");


Any way to get around this? Thanks!
Last edited on
Not simply, no. The best way would be to write a getline() variant that uses the original getline() to delimit properly. Basic algorithm:


Get a string using std::getline(), delimiting on the LAST character in your delimiter string, and append that to the result string.

If the end of the result string is the same as the delimiter string (sans the last character), then remove those characters from the result string and return it.

Otherwise, append the last character of the delimiter string to the result string and go to step 1.


Hope this helps.
Topic archived. No new replies allowed.