c++打印字符串的有哪些方法
在C++中,打印字符串可使用std::cout
流对象,也能够使用printf
函数。
使用std::cout
打印字符串的示例代码以下:
#include <iostream>
int main() {
std::string str = "Hello, World!";
std::cout << str << std::endl;
return 0;
}
使用printf
函数打印字符串的示例代码以下:
#include <cstdio>
int main() {
const char* str = "Hello, World!";
printf("%s
", str);
return 0;
}
TOP