\ in string

I'm having some problems with a string
im reading this in from a file and putting it in a string: '\n'
now i need to loop through it and remove the single quotes and the backslash,
so that the remaining string is just n
but when I use string.length(), it returns 5??
so I looked at each char in visual studio and I get
string[0] = '
string[1] = \
string[2] = n
string[3] = '
string[4] = 3435973836

can anyone explain why length() is returning 5, and why the unexpected 5th character is garbage?
well, i just wrote a test program testing this, and when the file just has that string, and all i do is read it in and test the length, it works fine.
Evidently I'm adding that character myself somewhere else in the program.
You could also have set the string's length to 5 somewhere (like the constructor).
ok, i found the offending code. when i just have a string with '\n' it works(gives me a length of 4)
but when I parse the '\n' from a whole line like this

 
isPal:	ldc '\n'


I get a length of 5 when I use this:
1
2
3
4
found = s1.find_first_of("\'");
quote = s1.substr(s1.find_first_of("\'"));
s1.erase(found);
 


the idea is to have 2 strings looking like this:

quote = '\n'
s1 = isPal: ldc

when I look at the strings in the debugger they look right, which is why I didn't realize that the length of quote is actualy 5 instead of 4.
i still can't figure out why substr is giving me a length of 5 instead of 4
null terminator...duh.
my eyes are blurry from looking at this project.
Topic archived. No new replies allowed.