int main(void) { return 0; }通常main()被启动代码调用,启动代码是由编译器添加到程序中的,而启动代码由操作系统调用。mian()里的()什么都没有,代表不接受任何参数。
#include编译指令#include导致预处理器在编译之前将iostream文件的内容与该行语句进行替换。
using namespace std;编译指令using,表示当前作用域内使用std名称空间。假设有两个公司G和S,他们都有一个方法f,那么如何区分呢?就用名称空间,即G::f()和S::f()就能区分了。当我们用using namespace G时,G::f()就可简写为f(),当然如果两家公司的方法要在同一个作用域内使用则要加上前缀区分。
using std::cout;这表示只使用std名称空间里的cout
#includeint main(void) { using namespace std; //using std::cout; //using std::endl; cout << "Come up and C++ me some time."; cout << endl; cout << "You won't regret it !" << endl; return 0; } cout是输出内容到屏幕,endl是换行
#includeint main(void) { using namespace std; int carrots; carrots = 25; cout << "I have " << carrots << " carrots " << endl; carrots -= 1; cout << "Now I have " << carrots << " carrots " << endl; return 0; }
#includeint main(void) { using namespace std; int carrots; cout << "How many carrots do you have ?" << endl; cin >> carrots; cout << "Here are two more." << endl; carrots += 2; cout << "Now you have " << carrots << " carrots." << endl; return 0; }



