目录
第一个程序"Hello world"
#include <iostream> //01hello.cpp
using namespace std;
int main(){
cout << "Hello world!" << endl;
return 0;
}
1.C++的编译器g++,如果使用gcc编译,需要带上 -std=c++0x,指定其使用标准C++的运行库
2.源文件扩展名:.cpp .cc .C .cxx .c++
-
最好使用.cpp
#include <iostream> //02hello.cc
using namespace std;
int main(){
cout << "Hello world!" << endl;
return 0;
}
3.头文件#include <iostream> iostream—— IO 流 (in out stream,输入输出流)
#include <iostream> //03hello.cpp 不使用名字空间
int main(){
std::cout << "Hello world!" << std::endl;
std::cout << 1919 << std::endl;
std::cout << 3.14 << std::endl;
std::cout << 2012 << "," << 1314 << "," << std::endl;
return 0;
}
-
C++中标准库文件一般都没有.h
-
当然也允许有.h
-
-
C++标准库中的内容放在一个叫做std名字空间中
-
using namespace std;
-
cout 对象 标准输出对象
-
cin 对象 标准输入对象
-
cerr 对象 标准错误输出对象
-
endl 对象 换行对象
-
-
#include <iostream> //04info.cpp
using namespace std;
int main(){
char name[40] = {};
cout << "input name:";
cin >> name;
int age = 0;
cout << "input age:";
cin >> age;
cout << "input salary:";
f