Linux下c++编程问题

wurong 2000-04-24 12:33:00
加精
1.在vc++下
#define ASSERT(e) if(!(e)){ throw "ERROR"; }

编译没有问题,但在linux,gcc编译,却在 换行继续符 '\'
给出 "stray '\' in program"的出错信息,why?
怎样解决?

2.linux下gcc编译:

#include <iostream>
using namespace std;
void main()
{
cout<<"dsf"<<endl;
}
包含头文件<iostream>没有错,
但gcc却说cout,(ostream&)<<(const char*)
undefined reference cout..

是gcc没有找到lib文件,还是什么问题?



...全文
317 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hem 2001-05-18
  • 打赏
  • 举报
回复
参考 , 有一个 dtox 的c 程序,挺简单的
#include <stdio.h>

void main(int argc, char *argv[])
{
FILE *fr,*fw;
char c;
if(argc!=3){
printf("Usage: %s dosfilename unixfilename\n",argv[0]);
return;
}
if(NULL==(fr=fopen(argv[1],"rb"))){
printf("文件%s不存在!\n",argv[1]);
return;
}
if(NULL==(fw=fopen(argv[2],"wb"))){
printf("不能写文件!\n");
return;
}
while(1){
c=fgetc(fr);
if(feof(fr))
break;
if(c=='\r')/*用'\r'来表示^M也不知道对不对,不对自己改*/
continue;
fputc(c,fw);
}
fclose(fr);
fclose(fw);
}

vagabond 2000-07-10
  • 打赏
  • 举报
回复
因为你用VC编辑的文件,结束是回车换行,所以gcc不认可。我经常碰到这个问题,编写了
一个小程序解决。

编译下面的程序,如:gcc -o delm delm.cpp
对于含有\^M 的文件,执行:delm exam.c即可。

#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <strstream.h>

main(int argc,char *argv[])
{
if(argc !=2)exit(1);
{
ifstream in(argv[1]);
if(! in){
cerr<<"Can't open file:"<<argv[1]<<endl;
exit(1);
}
ofstream out("/tmp/delm.tmp");
if(! out){
cerr<<"Can't open file:"<<argv[1]<<endl;
exit(1);
}
char ch;
while(in.get(ch)){
if(ch == 0x0d)continue;//skip '\M'
// if(ch == '\M')continue;//skip '\M'
// if(ch == '\Z')continue;//skip '\Z'
out.put(ch);
}
}
unlink(argv[1]);
ostrstream s;
s<<"mv /tmp/delm.tmp "<<argv[1]<<ends;
system(s.str());
exit(0);
}
brood 2000-05-11
  • 打赏
  • 举报
回复
#include <iostream.h>
solar 2000-05-10
  • 打赏
  • 举报
回复
好象gcc不允许续行符"\"后有空格.
wurong 2000-04-24
  • 打赏
  • 举报
回复
#define ASSERT(e) if(!(e)) { \ throw "error"; \ }
wurong 2000-04-24
  • 打赏
  • 举报
回复
1.在vc++下
#define ASSERT(e) if(!(e)){ throw "ERROR"; }




929 2000-04-24
  • 打赏
  • 举报
回复
如果是C++的话,用g++编译试试。

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧