1

Disclaimer: I am very new to C++; Java is my skillset.

In the program I'm writing, I need to compare two strings, as follows:

#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;
}

I understand that the buffer takes only "John" and "Doe" is a second, unrelated command. How can I stop the buffer from cutting off the second name? (Some names are 5 names long, some are just 1)

I've been fussing with getline(), but I guess I don't fully understand it--It doesn't wait for the input before plowing ahead.

Thanks in advance!

0

1 Answer 1

2

Use standard function std::getline. For example

std::getline( std::cin, find_name );
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.