最简单的c++程序:
#include<iostream> using namespace std; int main() { std::cout << "hello,world!" << std::endl; system("pause"); return 0; }
注解:
运行结果:
#include<iostream> using namespace std; int main() { //cout << "hello,world!" << endl; system("pause"); return 0; }
0返回给谁呢?返回给windows,告诉windows,我的程序正常运行,正常结束了。
下面输出一个变量v1:
#include<iostream> using namespace std; int main() { int v1; v1 = 12; cout <<"v1="<< v1 << endl; system("pause"); return 0; }
下面利用键盘动态输入变量v1:
#include<iostream> using namespace std; int main() { int v1; cout << "Enter a integer number:" ; cin >> v1; cout << "v1=" << v1 << endl; system("pause"); return 0; }
下面利用键盘动态输入2个数:
#include<iostream> using namespace std; int main() { int v1,v2; cout << "Enter a integer number:" ; cin >> v1; cin >> v2; cout << "v1=" << v1 << endl<< "v2=" << v2 << endl; system("pause"); return 0; }
原文:https://www.cnblogs.com/yibeimingyue/p/13379919.html