PeterNaut's blog

By PeterNaut, 9 years ago, In English

Do strings in c++ always end with null? If I have a string str = "hey";, will str[3] always be null? I only care about the index following the last character of the string, that is, I don't care what the value for str[4] is. :P

  • Vote: I like it
  • +9
  • Vote: I do not like it

»
9 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it
string s = "hey";
if (s[3] == NULL)
    cout << "ok";

output: ok

»
9 years ago, # |
Rev. 2   Vote: I like it +11 Vote: I do not like it

"If pos is equal to the string length, the function returns a reference to a null character ('\0')." It's posted here.