C&C++ recap

大一时候学过C++,可惜忘得差不多了,之后也很少用过。当时使用的是windows系统,使用的还是visual C++。当时对计算机并不感冒,也没好好学。最近在R的学习中遇到瓶颈,觉得要捡起曾经的C/C++。 现在早已时过境迁,系统换成mac,以前的知识也早已忘得一干二净,只能重头再来。

1. IDE

选择Eclipse CDT 还是不错的。几个注意的:

A. C和C++的不一致:

  创建源文件的话,C的结尾为.c, C++文件结尾为.cpp;

  语法也不一致,最简单的hello world就可以看到:

// C++ code

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

// C code
#include <stdio.h> // ".h" must be added for C
main(){
    printf("Hello World");
}

 

B. 编译器的选择:

  选择 MacOSX GCC 即可

  有的时候编译器有些问题,据说是与MacOS系统有关,试着双击一下binary file就work

  如果是直接使用编译器编译的话,也要注意C和C++文件的区别:

    

gcc helloworld.c # compile C source file
g++ helloworld.cpp # compile C++ source file

 

posted on 2015-04-20 05:52  Forever_YCC  阅读(331)  评论(0编辑  收藏  举报

导航