Write a C++ program that takes a string containing a full name, and outputs each part of the name separately. The name should be in the form of first, middle, and last name separated from each other by a single space. For example, if the name string contains
“John Jacob Schmidt”
then the program would output:
First name: John
Middle name: Jacob
Last name: Schmidt
I don't even know where to get started this is all I have.
1 2 3 4 5 6
#include <iostream>
#include <string>
usingnamespace std;
int main() {
Or you could have a loop that goes through the string and searches for the blank space in between and separates it from there.
There is also functions in C++ that will allow you to split the string into multiple pieces given certain characteristics. Just Google "C++ Split String".
no hes not because what the op also stated was he wants this for input:
John Jacob Schmidt
and the output to be this:
First name: John
Middle name: Jacob
Last name: Schmidt
cin>> FirstName >> MiddleName >> LastName would do that. of course the names would be different if he chooses, but thats all he needs. cin grabs from the buffer until it reads a space. what do you think getline is for?