*edit*
Nevermind, it looks like I just needed to add a backslash:
----------------------------Code:found = str.find("\\n");
I'm searching for a sequence of characters in a string. I figured .find() would be my best bet. I can get it to work for most cases, except when I try to look for the following sequence of characters "\n".
So, my example string might look like:
*Note, the "\n" is actually in the text file. So, the above string would look exactly as it does now - all on one line.Code:The dog crossed \nthe street and he \nbarked at the neighbor.
I can find other sequences of characters no problem. For example:
This will return the correct position. However, if I do:Code:int found = -999; found = str.find("do"); cout << found << endl;
It will return -1.Code:int found = -999; found = str.find("\n"); cout << found << endl;
I know it has something to do with '\n' representing newlines, but I can't quite figure out how to actually find "\n" in the string.
In case you are wondering, I am just trying to replace any occurences of "\n" with an actual new line.
So my output would look like:
Maybe there is a better way to do this?Code:The dog crossed the street and he barked at the neighbor.
Any ideas?



LinkBack URL
About LinkBacks



