#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ofstream file("C:/cdp_test_in.txt");
file << "china, china." << endl;
file << "hello, world." << endl;
file << "great, anhui." << endl;
file.close();
FILE *newIn = NULL, *newOut = NULL;
freopen_s(&newIn, "C:/cdp_test_in.txt", "r", stdin);
freopen_s(&newOut, "C:/cdp_test_out.txt", "w", stdout);
char buffer[20];
while(gets(buffer))
puts(buffer);
if(newIn)
fclose(newIn);
if(newOut)
fclose(newOut);
return 0;
}
执行完毕后可以在C:目录下找到那两个文件,检查一下,记得删除啊。
把控制台输入输出重定向到磁盘文件的C++方法
最新推荐文章于 2022-09-21 12:33:49 发布