C++ 项目赢得';不允许2个输入?

C++ 项目赢得';不允许2个输入?,c++,input,C++,Input,所以我试图让用户输入他们的名字和身高 我有其他密码 我有这个 #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int name1; cout << "What's your name?"; cin >> name1; int height1; cout << "Wh

所以我试图让用户输入他们的名字和身高

我有其他密码

我有这个

#include <iostream> 
#include <string> 
#include <algorithm> 
using namespace std; 

int main() 
{ 
int name1; 
cout << "What's your name?"; 
cin >> name1; 

int height1; 
cout << "What's your height?"; 
cin >> height1; 

return 0; 
} 
#包括
#包括
#包括
使用名称空间std;
int main()
{ 
国际名称1;
cout>name1;
内部高度1;
cout>height1;
返回0;
} 

问题是它不允许用户输入他们的身高。有什么想法吗

问题是,您使用的是int变量而不是std::string。但是,您已经包含了
头文件,因此可能需要执行以下操作:

#include <iostream> 
#include <string> 
#include <algorithm> 
using namespace std; 

int main() 
{ 
std::string name1; 
cout << "What's your name?"; 
cin >> name1; 

std::string height1; 
cout << "What's your height?"; 
cin >> height1; 

return 0; 
} 
#包括
#包括
#包括

#包括
#包括
#包括
使用名称空间std;
int main()
{ 
std::字符串名称1;

你能把
name1
作为
int
吗?这是错误的。而且,
cin>
输入是用空格分隔的。那么如果我键入
Bob T.Fish“
,会发生什么情况呢?(也就是说,它有点坏了)多个词不能用,他会想要GETLION。但是作为C++流的一个快速介绍,这还不错。请同时提到使用<代码> STD::GETLION<代码>谢谢,我还添加了一个STD::GETLIN!@ TykHoer-Help到堆栈溢出的解决方案。请不要留下评论,只想说“谢谢”。。如果此答案解决了您的问题,请将此答案标记为已接受-谢谢。
#include <iostream> 
#include <string> 
#include <algorithm> 
using namespace std; 

int main() 
{ 
std::string name1; 
cout << "What's your name?"; 
getline(cin, name1);

std::string height1; 
cout << "What's your height?"; 
getline(cin, height1);

return 0; 
}