#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string input_filename = "D:\\MVCVAE\\input.txt";
ifstream input(input_filename);
if (input.is_open()) {
cout << " input.txt文件成功打开" << endl;
input.close();
}
else
{
cout << " input.txt文未成功打开, 正在创建文件output.txt ...." << endl;
string output_filename = "D:\\MVCVAE\\output.txt";
ofstream output(output_filename, iostream::out);
output.close();
}
return 0;
}
参考链接 https://blog.csdn.net/qq_38153833/article/details/122218460
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string input_filename = "D:\\MVCVAE\\input.txt";
string output_filename = "D:\\MVCVAE\\output.txt";
string tmp_str;
ifstream input;
ofstream output;
input.open(input_filename);
if (input.bad())
cout << "文件没打开" << endl;
output.open(output_filename, ios::app);
while (!input.eof())
{
input >> tmp_str;
cout << "临时数据:" << tmp_str << endl;
;
output << tmp_str << " " << endl;
}
input.close();
output.close();
return 0;
}
|