在用 freopen 打开一个文件后,一直 getline 到 EOF。
再用 freopen 打开另一个文件,就读入不了。
例如:
#include <bits/stdc++.h>
using namespace std;
signed main() {
freopen("std.cpp","r",stdin);
while(getline(cin,s)) {
for(char i:s) {
printf("%c",i);
_sleep(5);
}
puts("");
}
freopen("my.cpp","r",stdin);
while(getline(cin,s)) {
for(char i:s) {
printf("%c",i);
_sleep(5);
}
puts("");
}
return 0;
}
在 getline 到第一个文件的 EOF 后,打开第二个文件,就读入不了。
请问怎么解决?