I'm trying to print a string the following way:
int main(){ string s("bla"); printf("%s ", s); ....... }
but all I get is this random gibberish.
Can you please explain why?
Because %s indicates a char*, not a std::string. Use s.c_str() or better still use, iostreams:
%s
char*
std::string
s.c_str()
#include <iostream> #include <string> using namespace std; int main() { string s("bla"); std::cout << s << " "; }
1.4m articles
1.4m replys
5 comments
57.0k users