Help with Run-time error using map and printf C++

Question answered, thanks to all!

This is because printf("%s") expects a C-style string, not std::string

To fix it

  1. Use cout as it is much safer than printf, and can handle your own types (if you have overloaded operator<< for std::ostream)

  2. Or if you want to do it using printf, you can do A[5].c_str() to obtain C-style string.

    printf("%s", (*it).second.c_str()); //works

3 Likes

So we have the answer, but not the question… What was it ?

1 Like
//