I am getting this error when running:
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr:
I am brand new, any other tips would be appreciated as well.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int position = 1;
string letter;
cout << "Enter in your full name seperated by a space: ";
getline (cin, name);
cout << name.substr(0, 1);
while (position <= name.length())
{
position++;
letter = name.substr(position, 1);
if (letter == " ")
{
cout << name.substr(position + 1, 1) << " ";
}
}
cout << endl;
return 0;
}