Hi All. I am needing some assistance setting up this program. I would like it to show the 1st initial of each the first, middle and last name. I would also like it to print the first 3 letters of the person's middle name on the fifth line, print the eighth character in the persons full name on the sixth line, and print the total number of characters in the person's name (including the spaces) on the seventh line.
Here would be the ideal outcome:
Enter a name in the format First Middle Last: James Tiberius Kirk
James
Tiberius
Kirk
JTK
Tib
i
19
Here is what I have so far:
#include <iostream>
#include <string>
using namespace std;
char chr;
int main()
{
string first, middle, last;
cout << "Enter your first name, middle name, and last name" << endl;
cin >> first name >> middle name >> last name;
cout << string.substr
#include <iostream>
#include <string>
int main()
{
std::string first, middle, last;
std::cout << "Enter your first name, middle name, and last name" << std::endl;
std::cin >> first >> middle >> last;
//Output each part of the name
//Output the first character of each part of the name (hint use the .at() function)
//Use middle.substr()
//Turn them all into one single string using += (don't forget to add the spaces)
//Output the eighth character using .at()
//Count the length of the name
return 0;
}
I tried that first += ' ' + middle + ' ' + last, but that gave me a run time errorUnhandled exception at 0x7647DAE8 in Sub String.exe: Microsoft C++ exception: std::out_of_range at memory location 0x00AFF458. Using Visual Studio 2015. Solved the problem with temp = first + ' '.... Of course it was late and I did not want to figure it out right then.
Do not know if it will make any difference or if it was just something I did wrong.