You need to understand the difference between compile-time and runtime with respect to C++ types. This is a basic fundamental of the C++ and 'C' language.
Code:
#include <string>
#include <iostream>
using namespace std;
int main()
{
std::string s;
cout << sizeof(s) << "\n";
s = "abc123456789123456789xyz";
cout << sizeof(s) << "\n";
}
What results do you get? You see that sizeof(s) is the same, regardless of what you do at runtime to the string? The sizeof(string) doesn't magically change from 0 to 24 just becase it now contains 24 characters.