私は次のコードを持っています、
#include<stdio.h>
#include<stdlib.h>
int main()
{
//freopen("file1","w",stdout);
char str[]="command line with file";
char s[]="extra string";
puts(str);
puts(s);
system("PAUSE");
return 0;
}
コンソールに出力を表示すると、次のように表示されます。
command line with file
extra string
Press any key to continue . . .
また、コード内のコメント行を削除してファイルに出力を書き込む場合も、同じ出力が期待されます。しかし、それは次のように出力します、
Press any key to continue . . .
command line with file
extra string
なぜこのファイルとコンソール出力の違いは?ここでは、system( "PAUSE")関数が文字列出力を担当しますPress any key to continue . . .