免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1621 | 回复: 4
打印 上一主题 下一主题

代码在VC++上可以编译但是在GCC就不可以 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-02 18:12 |只看该作者 |倒序浏览
写了个复制文件内容的代码为什么在GCC就编不通呢》???
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5. ifstream open_file_in(string str)
  6. {
  7.         ifstream fin;
  8.         fin.open(str);
  9.         return fin;
  10. }
  11. ofstream open_file_out(string str)
  12. {
  13.         ofstream fout;
  14.         fout.open(str,fstream::out|fstream::app);
  15.         return fout;
  16. }
  17. int main(void)
  18. {
  19.      string file_name;
  20.          cout<<"pealse input a filename and its path"<<endl;
  21. inputname:         cin>>file_name;
  22.          ifstream fin;
  23.          fin=open_file_in(file_name);
  24.          int no=0;
  25.          if(!fin)
  26.          {
  27.                  no++;
  28.                  if(no!=3)
  29.                  {cerr<<"the filename is wrong please input a filename again"<<endl;
  30.                  goto inputname;
  31.                  }
  32.                  else
  33.                  {
  34.                          cerr<<"the program will close"<<endl;
  35.                          exit(1);

  36.                  }
  37.          }
  38.      ofstream fout;
  39.          string out_file;
  40.          cout<<"please output a file name for output"<<endl;
  41.          cin>>out_file;
  42.          fout=open_file_out(out_file);
  43.          string tmp;
  44.         while(getline(fin,tmp))
  45.         {
  46.                 fout<<tmp;
  47.         }
  48.         fin.close();
  49.         fout.close();
  50.     return 0;
  51. }
复制代码

论坛徽章:
4
丑牛
日期:2014-01-11 15:11:12亥猪
日期:2014-12-15 22:19:092015年辞旧岁徽章
日期:2015-03-03 16:54:152015年亚洲杯之约旦
日期:2015-03-13 19:45:11
2 [报告]
发表于 2012-03-02 23:10 |只看该作者
貌似应该用g++编译吧,gcc是用来编译c语言的,你试下g++编译

论坛徽章:
0
3 [报告]
发表于 2012-03-03 02:57 |只看该作者
gcc编译c++代码要加上-lstdc++

论坛徽章:
0
4 [报告]
发表于 2012-03-03 17:42 |只看该作者
g++

论坛徽章:
0
5 [报告]
发表于 2012-03-05 19:01 |只看该作者
我就是用g++编译
找到问题了
fstream:pen()不可以传递字符串 得用字符串指针。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP