65,168
社区成员




#include <fstream>
#include <string>
int main() {
std::ofstream outFile("data.txt");
if (!outFile) {
// 处理文件打开失败的情况
return 1;
}
// 写入数据
outFile << "Hello, World!" << std::endl;
outFile << "Another line of text." << std::endl;
int main(){
// 文件会在outFile对象析构时自动关闭,但也可以显式关闭
outFile.close();
std::ifstream inFile("data.txt");
std::string line;
inFile.close();
}
return 0;
}
这是保存代码。