C++ 标准输出cout与printf

C++标准输出cout与printf都可以,printf用法更死板一些。

#include <iostream>

int main(int argc, char** argv) {
using namespace std;
#普通输出
cout<<"This is cout"<<endl;
printf("This is printf\n");

    #如果要输出字符串,则printf记得加上c_str(),把std:string转成const char*
string mystring=&quot;my_defined_string&quot;;
cout&lt;&lt;mystring&lt;&lt;endl;
printf(&quot;This is printf: %s&quot;,mystring.c_str());
return 0;

}

posted @ 2014-08-03 10:31  MindProbe  阅读(11670)  评论(0编辑  收藏  举报