codeblocks不能读写文件,怎么办?

#include <fstream>
#include <iostream>
using namespace std;

int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
ofstream fout("G:\\fuck.txt",ios::out);
for(int i=0;i<10;i++)
fout<<a[i]<<endl;
fout.close();
return 0;
}

同样的代码,在codeblocks下运行,什么都没有,用vc++6.0运行,可以创建文件并写入数据,why?

用以下代码试一下:
#include <fstream>
#include <iostream>
using namespace std;
#include <windows.h>
int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
ofstream fout("G:\\fuck.txt",ios::out);
if ( fout.fail() )
{
cout << "open file error\n";
cout <<"errno: " <<GetLastError () <<endl;
return -1;
}
/*
for(int i=0;i<10;i++)
fout<<a[i]<<endl;
fout.close();
*/
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-21
你看看你的CB配置,我能正常运行。
我是CB+GCC5
相似回答