免费注册 查看新帖 |

Chinaunix

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

问个弱智的问题,为什么#include无效? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-05 12:15 |只看该作者 |倒序浏览
test.cc:

#include <stdio.h>;
#include <stdlib.h>;

int main()
{   int ch;
    while( ch = getch() ) {
                 cprintf("key is: ch \r\n";
            break;  }
            return 0;
}

程序很小,但就是不知道怎么运行。
在远程linux上输入gcc test.cc
结果:
test.cc:1: undefined or invalid # directive
test.cc:2: undefined or invalid # directive
test.cc: In function `int main()':
test.cc:6: implicit declaration of function `int getch(...)'
test.cc:7: implicit declaration of function `int cprintf(...)'

该怎么办呀

论坛徽章:
0
2 [报告]
发表于 2005-01-05 12:29 |只看该作者

问个弱智的问题,为什么#include无效?

希望你明白,unix/linux下stdio里没有getch()函数,好像curses里有,但它的用法显然与DOS下、WINDOWS下的不一样。
可以换用getchar()

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
3 [报告]
发表于 2005-01-05 12:46 |只看该作者

问个弱智的问题,为什么#include无效?

我想知道为什么会出现这样的错误:
test.cc:1: undefined or invalid # directive

论坛徽章:
0
4 [报告]
发表于 2005-01-05 12:51 |只看该作者

问个弱智的问题,为什么#include无效?

你确信自己包含头文件的#include拼写正确吗?有可能是拼写错误。
还有,C程序不要命名为.cc,那是C++程序,用g++命令编译-连接的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP