第一個C++程序,Hello world
#include <iostream>
using namespace std;
int main()
{
cout << "Hello,world!"<endl;
return 0;
}
這裏和C的區別是#include <iostream> ,C裏面頭文件都是.h結尾,這裏沒有;
有一個典故,在iostream這個lib出現之前已經有了iostream.h這個lib,爲了和iostream.h區分,就把.h去掉了,所以iostream和iostream.h是不同的lib
cout means standard output.
<< 輸出符,將右邊的內容輸入到左邊的流中,endl means end of line.
在eclipse開發,先創建項目(c++ project),主流的IDE都需要創建項目,然後進行開發。
在src目錄右鍵創建c++ source file,粘貼上面的代碼,編譯(build project),運行(run as Local c/c++ application)., console 顯示輸出內容(hello world!)
用g++運行
保存源代碼文件helloworld.cpp
g++ helloworld.cpp
./helloworld.out
iostream這個LIb包含基本的:cout cin endl 等。