社区讨论
C++中的所有输出方式
学术版参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lz8az6sh
- 此快照首次捕获于
- 2024/07/30 18:56 2 年前
- 此快照最后确认于
- 2024/07/30 20:06 2 年前
1.使用标准输出流std::cout:
C#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
2.使用printf函数(来自C语言):
C#include <cstdio>
int main() {
printf("Hello, World!\n");
return 0;
}
3.使用字符串流std::stringstream:
C#include <sstream>
#include <iostream>
int main() {
std::stringstream ss;
ss << "Hello, World!";
std::cout << ss.str() << std::endl;
return 0;
}
4.使用std::ofstream写入文件:
C
#include <fstream>
int main() {
std::ofstream outFile("output.txt");
if (outFile) {
outFile << "Hello, World!" << std::endl;
}
return 0;
}
大抵是太久没有编程了,近夜来手指愈发冰凉,只有在键盘上敲击,才能......
以上便是我所知的所有输出方式了,虽然我通常只用前两种......
回复
共 5 条回复,欢迎继续交流。
正在加载回复...