Как в С++ перенаправить cin и cout в файл?
myprog.exe < input.txt > output.txt
ofstream* logfile;
streambuf* clogbuf;
logfile = new ofstream("__log.txt");
streambuf *logbuf = logfile->rdbuf;
clogbuf = clog.rdbuf;
clog.rdbuf(logbuf);
Читай до просветления.
Можно --- только функции main.
---
...Я работаю антинаучным аферистом...
Там C++?
в лиспе используется тот же приём.
---
"Narrowness of experience leads to narrowness of imagination."
В лиспе есть cin и cout?
Не знаю, че за фигню несет Контра, но, скорее всего, он имел в виду, что нужно закрыть 0 и 1 дескрипторы и открыть на них другие файлы.
В схеме они называются current-input-port и current-output-port,
а в общем шёпоте --- *standard-input* и *standard-output*.
---
"Narrowness of experience leads to narrowness of imagination."
STANDARDS
The fopen and freopen functions conform to ANSI X3.159-1989
(``ANSI C89'').
---
"...Аллах не ведёт людей неверных."
#include <fstream.h>
.......
int main
{
ofstream cout("output.txt");
ifstream cin("input.txt");
cout<<"какая-нибудь ня"<<endl;
int a;
cin>>a;
return 0;
}
писец.
могу предложить свой
freopen("gagaga.txt","w", stdout);
std::cout << "YO nigga!" << std::endl;
fclose(stdout);
Оставить комментарий
OlegXXL
сабж