I am wondering how come the sizeof function returned 8 no matter the length of my input
int main(){
string input;
getline(cin,input);
cout << "size of input is " << sizeof(input) << endl; //I am guessing
//it returns the size of a pointer because my OS is 64 bits.
return 0;
}
So my question is that where the implicit conversion happened? here is the declaration of getline,
istream& getline ( istream& is, string& str );
Also, this sort of conversion always happen, i.e from whatever to a pointer type, is there a general case for that? Thank you.
input.size()...sizeof(input)is the size of anystd::stringobject, not thatstd::string's contained data.sizeof(input)is certainly larger thansizeof(void*)or any other pointer type.operator const char *()to myStringclass. You can get that usingc_str()of course here though.sizeof's behavior though.