mercredi 31 juillet 2019

How does the ostream class object behaves on single parameter string input?

I was exploring ostream class in C++. I am stuck on strange output of cout object on string and integer datatype.

While passing an integer or a floating value, the output is exactly what i pass. for eg cout.operator<<(10); prints "10". But while using string as argument it is printing some hexadecimal values.

#include <iostream>
#include <string>

using namespace std;

int main() {
        const char* str = "aia";
        cout.operator<<(str);
        return 0;
}

output when string is passed: 0x4007e0 and the output is same for various strings i tried to pass.

Aucun commentaire:

Enregistrer un commentaire