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


想知道这个问题如何解决,谢谢!
你用的编译器有问题吧?不要用gcc,要用g++编译,且文件后缀不要用c,要用cpp。
可参照网络教程配置环境变量
环境变量配置了吗
你先运行一个最简单的看看有没有问题
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream fin("config.txt");
if(fin)
cout<<"ok"<<endl;
else
cout<<"fail"<<endl;
fin.close();
//cout<<"whathappen";
return 0;
}
试下这样?我不确定,因为我的编译器是可以的
ide配置好了吗?
1、重装一下相关 IDE 试一下,看是否是软件的问题。
2、不是软件的问题也不是代码问题,可能是系统出现了问题,可以看看下面的教程,看看能否正常修复。
把编译器MinGW GCC11.2.0 64-bit Debug换成了MinGW GCC11.2.0 64-bit Release,现在运行没问题了,谢谢大家!