| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6953 人关注过本帖
标题:一个在VC++中 后缀名为 .C 和 'CPP 的区别?
取消只看楼主 加入收藏
wgkrd
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-5-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
一个在VC++中 后缀名为 .C 和 'CPP 的区别?
#include <stdio.h>
int main(void)
{
    for(int i=0; i<10; i++)
    {
        printf("%d\n",i);
    }
    return 0;
}

分别命名为 main.c 和 main.cpp
命名为main.cpp 时正常.
当命名为 main.c 时报错,报错信息如下,
Compiling...
main.c
D:\workspace\test\1.c(5) : error C2143: syntax error : missing ';' before 'type'
D:\workspace\test\1.c(5) : error C2143: syntax error : missing ';' before 'type'
D:\workspace\test\1.c(5) : error C2143: syntax error : missing ')' before 'type'
D:\workspace\test\1.c(5) : error C2143: syntax error : missing ';' before 'type'
D:\workspace\test\1.c(5) : error C2065: 'i' : undeclared identifier
D:\workspace\test\1.c(5) : warning C4552: '<' : operator has no effect; expected operator with side-effect
D:\workspace\test\1.c(5) : error C2059: syntax error : ')'
D:\workspace\test\1.c(6) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)

为什么?我是新手,请大学不吝指教.
搜索更多相关主题的帖子: return test 
2011-05-22 11:20
wgkrd
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-5-22
收藏
得分:0 
回复 2楼 liangjinchao
也就是说在在命名为 main.c 时,修改代码为
#include <stdio.h>
int main(void)
{
    int i;
    for(i=0; i<10; i++)
    {
        printf("%d\n",i);
    }
    return 0;
}
是可以正常运行的,为什么改了以后就不行了,原因是什么呗?
2011-05-22 11:24
快速回复:一个在VC++中 后缀名为 .C 和 'CPP 的区别?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017870 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved