c++读取输入的几种方法:cin、cin.get()、cin.getline()、getline()、gets()、getchar()
1.cin
#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"please input the value of x and y:"<<endl;
cin>>x>>y;
cout<<"x+y="<<x+y<<endl;
return 0;
}
输入:3【空格】【空格】4 或者 3【enter】【enter】4
输出x+y=7
说明:cin遇空格或者enter键停
#include<iostream>
using namespace std;
int main()
{
char a[20],b[20];
cout<<"please input the value of a and b:"<<endl;
cin>>a>>b;
cout<<a<<endl<<b<<endl;
return 0;
}
输入:zhongyelove【blank】liuye
输出:zhongyelove
liuye