cin cout是c++中的标准输入输出流。
一、cin
cin的一般用法:
cin>>变量a
例如:
#include <iostream>
using namespace std;
// using namespace std;
int main()
{
int UserInput;
cin >> UserInput;
cout << "you input a number is "<< UserInput<<endl;
return 0;
}
cin会自动辨别变量的类型,如a可以是char,b可以是int,c可以是float。
接收字符串时,遇到空格,tab键和换行符都会结束接收。
二、cout
cout<<表达式
cout<<变量
cout<<字符串
cout默认不换行,推荐使用endl来换行
例如:
int Example_Cout()
{
int UserInput;
UserInput=105;
cout<<1+1<<endl;//cout输出表达式
cout<<UserInput<<endl;//cout输出变量
cout<<"Hello";//cout输出字符串
return 0;
}
三、cin.get
Cin.get可用于程序暂停
四、Cout<<A<<B<<C可用于字符串的拼接
int Example_AddString(){
cout<<"Hello "<<"World";
return 0 ;
}