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;

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM