大一新生,写了一段关于文件读取的c++代码,经检验无误,但在小熊猫c++上无法正确运行。
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream fin;
fin.open("config.txt");
if(fin)
cout<<"ok"<<endl;
else
cout<<"fail"<<endl;
fin.close();
cout<<"whathappen";
return 0;
}
运行结果如图:

改用codeblock,仍然无法运行。


换了一段代码,用codeblock仍然无法运行。
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("D:/Data/test.txt","r",stdin);
freopen("D:/Data/test2.txt","w",stdout);
string s;
while(cin>>s){
cout<<s<<endl;
}
}
运行结果如图:


想知道这个问题如何解决,谢谢!