C++ 如何停止cin>&燃气轮机;使用C+;只需输入而不键入单词+;?
为什么即使我按enter键,cin也会不断提示C++ 如何停止cin>&燃气轮机;使用C+;只需输入而不键入单词+;?,c++,C++,为什么即使我按enter键,cin也会不断提示 #include <iostream> using namespace std; int main(){ string name = ""; cout << "What's your name?"; cin >> name; cout << "Hello ""; if (name == "") cout << "World!";
#include <iostream>
using namespace std;
int main(){
string name = "";
cout << "What's your name?";
cin >> name;
cout << "Hello "";
if (name == "")
cout << "World!";
else
cout << name + "!";
return 0;
}
#包括
使用名称空间std;
int main(){
字符串名称=”;
姓名;
coutcin>>name;
会一直读取,直到输入内容。您需要一个只读取一行的函数。该函数称为getline
#include <iostream>
#include <string>
using namespace std;
int main(){
string name = "";
cout << "What's your name?";
getline(cin, name);
cout << "Hello "";
if (name == ""){
cout << "World!";
else
cout << name + "!";
return 0;
}
#包括
#包括
使用名称空间std;
int main(){
字符串名称=”;
什么是字符串?哦,是打字错误。只是string@Jay,请编辑您的问题并纠正错误