コンソール入出力をディスクファイルにリダイレクトするC++メソッド


#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:          ,    ,     。