Search code examples
c++stringtypestypeinfo

Strange output when checking typeinfo of a string


When checking the typeinfo of a String in c++, it returns a strange output A19_c, what does the A19_c mean?

When explicitly initialized as a referenced type string, it works find and returns an Ss.

#include <iostream>
#include <typeinfo>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   

    std::string mystr = "I am a code monkey";
    cout << typeid(mystr).name() << endl;
    cout << typeid("I am a code monkey").name() << endl;
    return 0;
}

[out]:

Ss
A19_c

Solution

  • type_info::name is not required to return anything human readable. It is an implementation-defined name. It isn't even required to be unique. So the exact meaning of it depends on the implementation. Also, you're not guaranteed to get A19_c from any other implementation.