【发布时间】:2014-10-29 05:01:14
【问题描述】:
免责声明:我对 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(),但我想我并不完全理解它——它不会等待输入才继续前进。
提前致谢!
【问题讨论】: