<分区>
免责声明:我是 C++ 的新手; Java 是我的技能组合。
在我写的程序中,我需要比较两个字符串,如下:
#include<string>
#include<iostream>
using namespace std;
int main()
{
string full_name = "John Doe";
string find_name;
//User inputs "John Doe"
cout << "Enter the name of the person to search for:" << endl;
**cin >> find_name;//THIS IS THE ISSUE I HAVE**
if(find_name == full_name) //or some other compare function. NOT THE ISSUE.
action_do_something;
return 0;
}
我知道缓冲区只接受“John”,而“Doe”是第二个不相关的命令。如何阻止缓冲区切断第二个名字? (有的名字有 5 个名字,有的只有 1 个)
我一直在研究 getline(),但我想我还没有完全理解它——它不等待输入就继续进行。
提前致谢!