码迷,mamicode.com
首页 > 系统相关 > 详细

Linux中gcc和g++

时间:2014-10-13 19:52:56      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   文件   

    今天在Linux上编写一个小的C++程序运行,需要用到iostream中cout,一开始创建一个hello.c的文件编写如下代码:

bubuko.com,布布扣
 1 #include<stdio.h>
 2 #include<sys/types.h>
 3 #include<unistd.h>
 4 #include<iostream>
 5 using namespace std;
 6 int main()
 7 {
 8    int i;
 9    for(i=0;i<3;i++)
10    {
11       fork();
12       //printf("H");
13       cout << "H";
14    }
15    return 0;
16 }
View Code

   通过gcc编译该代码会出现错误,没法通过。然后我联想到在windows下的c++源文件都是.cpp类型的,我想是不是自己文件后缀有问题,因此改为hello.cpp,然后再次编译,还是没法通过(我是用gcc编译)。。。几次折腾后,我突然想起Linux下还有一个g++的编译工具,我就用g++试了一次。。嘿嘿,这次没问题了。。

   从这个小小的实例知道,Linux下C和C++还是需要很好去别的。。。

Linux中gcc和g++

标签:style   blog   http   color   io   os   ar   for   文件   

原文地址:http://www.cnblogs.com/LCCRNblog/p/4022654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!