why stringsteam.str().c_str() is not giving expected results?

52 Views Asked by At

I don't know how to ask this question as this looks very trivial, but surprisingly it's not working in my project in the visual studio. It works in the sample program. Does any optimization flag are the reason behind this?

    std::ostringstream s;
    s << "player";
    s << 1;
    cout << s.str() << endl;
    const char* pStr = s.str().c_str();
    cout << pStr<<endl;

In sample program it outputs

    player1  
    player1

but in my project const char* pStr is having "" value. Can anyone provide suggestions on what might be happening here?

0

There are 0 best solutions below