免责声明:我是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(),但我想我并不完全理解它-它不会在犁耕前等待输入。
提前致谢!
使用标准功能std::getline
。例如
std::getline( std::cin, find_name );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句