This is a rather simple problem but is pretty confusing.
string R = \"hhhh\" ;
cout<< sizeof( R )<
OUTPUT:
4
sizeof expression
returns the size required for storage of the type expression evaluates to (see http://en.cppreference.com/w/cpp/language/sizeof). In case of std::string
, this contains a pointer to the data (and possibly a buffer for small strings), but not the data itself, so it doesn't (and can't) depend on string length.