How to print a string in C++

node ninja picture node ninja · Mar 16, 2011 · Viewed 415.9k times · Source

I tried this, but it didn't work.

#include <string>
string someString("This is a string.");
printf("%s\n", someString);

Answer

GWW picture GWW · Mar 16, 2011
#include <iostream>
std::cout << someString << "\n";

or

printf("%s\n",someString.c_str());