0

It seems that it's not separating the word within the space.

Trying to separate the words in between, and stored it in first and second.

cin >> name; //input name 
stringstream file (name);
getline(file,first, ' '); //seperate the name with the first name and last name using space 
getline(file,second, ' ');
vidit
  • 6,293
  • 3
  • 32
  • 50
user1745860
  • 207
  • 1
  • 5
  • 11

2 Answers2

3

Replace

cin >> name;

with

getline(cin, name); //input name

cin >> reads only upto the first space. You would have realized this if you done a cout << name; to check what's getting read - this is the first step of debugging.

user93353
  • 13,733
  • 8
  • 60
  • 122
2

When you read the initial input with cin >> name; that only reads up to the first white space character.

You then try to break that into two pieces at white space, which it doesn't contain.

Easy way:

cin >> first >> second;

Alternatively, if you start with std::getline(cin, name); instead of cin >> name;, then the rest should work correctly.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111