Pallav singh said:
why should we do string allocation with '\0' in STL ? is it something
related to Backward compaitity to C ?
1- Nothing says that std::string uses '\0' to mark the end of the string.
2- "abc" is specified by C and for backward compatibility, by C++ to
be and array of char containing 'a', 'b', 'c' and '\0'. This is
necessary, since C++ didn't want to add a string basic type, or to
map the "..." syntax to a call to std::string.
3- You don't have to use the C syntax "abc". You can write:
std::string s; s.push_back('a'); s.push_back('b'); s.push_back('c');
// Look Ma! No '\0'!
4- You may write a pre-processor to expand any occurence of "abc" into:
{static char temp[3]={'a','b','c'}; return std::string(temp,3);}