fstream流对象形参时出现的错误问题(codeblocks+gcc)

有如下程序:

#include <iostream> #include <fstream> using namespace std; void fuc(ofstream file){ file<<"jarvischu"<<endl; } int main(int argc,char* argv[0]) { for(int i=0;i<argc;i++){ cout<<argv[i]<<endl; } ofstream file("test.txt"); fuc(file); return 0; } 

编译连接时报错:

fstream流对象形参时出现的错误问题(codeblocks+gcc)_第1张图片

出错的原因我目前还不知道,以后再找。

解决方法:

将代码改成如下形式:

#include <iostream> #include <fstream> using namespace std; int main(int argc,char* argv[0]) { for(int i=0;i<argc;i++){ cout<<argv[i]<<endl; } ofstream file("test.txt"); file<<"jarvischu"<<endl; return 0; } 

 

你可能感兴趣的:(gcc,File)