Could someone help me with a code I've been having some difficulty with? With this code, I should be able to take a string with a full name and output the names one at a time. So, for example, the name "John Doe" would output to "First Name: John" "Last Name: Doe". This is what I have so far, and I haven't been able to get it to work yet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
#include "stdafx.h"
usingnamespace std;
int main()
{
string name = "John Jacob Schmidt";
int index;
index = name.find(' ');
cout << "First Name: " << name.substr(0, index) << endl;
name = name.substr(index+1, name.length()-1);
index = name.find(' ');
cout << "Middle Name: " << name.substr(0, index) << endl;
name = name.substr(index+1, name.length()-1);
cout << "Last Name: " << name;
return 0;
}