D25. 输入输出
在C语言里,如果要输入是scanf("%d",&a),输出是printf("%d",a)
而在C++里面则是cin cout 来表示
#include <iostream>using namespace std;int main() {int a;cin>>a;a=a+3; cout << a << endl; return 0;}
其中endl的意思是end-of-line,也就是换行\n,要特别注意的是<< >>的方向,<< 是 output operator, 把右边的资料,传送给其左边的cout
试一下换行的用法
#include <iostream>using namespace std;int main() {int a=3; cout << a << " "; cout << a+3 << " "; cout <<"next line" <<endl;cout << a+5<<endl; return 0;}
输出内容
(而在cout 到endl 之间的空格除非有用双引号隔出的才会显示)