方法一:
#include<iostream>
#include<string>
using namespace std;
int main()
{
char ch[3];
cin.getline( ch,3 );
cout<<ch<<endl;
system("pause");
}
结果:
方法二:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string ss;
getline(cin,ss);
cout<<ss<<endl;
system("pause");
}
结果:
方法三:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string strWithSpace;
string strTmp1,strTmp2;
cin>>strTmp1>>strTmp2;
strWithSpace = strTmp1+" "+strTmp2;//要加几个空格自己添加
cout<<strWithSpace<<endl;
system("pause");
}
结果: