I am getting a runtime error somewhere in the inputData function, I can't find it. Can anyone help? Thanks
#include <iostream>
#include <string>
using namespace std;
void inputData (string &); //function prototype passing by reference
void outputData (string); //function prototype passing by value
int main()
{
string myString; //instantiates a string called myString
cout << "Enter a name format: (Last, First Middle) : ";
cin >> myString;
inputData( myString ); //calls inputData function passes myString by reference
outputData( myString ); //calls function outputData passes myString by value
//myString's data was changed by inputData function
return 0;
} // end main
// function inputData receives myString by reference then rearranges name using find(),
// substr(), length(), insert(), erase().
void inputData(string &aString)
{
int length = aString.length();
string lastName = aString.substr(0, aString.find(',') -1);
string firstName = aString.substr(aString.find_first_of(' ') +1 , aString.find_last_of(' ') -1 );
int firstLength = firstName.length();
string middleName = aString.substr(aString.find_last_of(' '), length );
int middleLength = middleName.length();
string middleInitial = middleName.erase( 1, middleLength - 2 );
lastName.insert(0, " ");
middleInitial.insert( 0, " ");
aString = firstName + middleInitial + lastName;
cout << aString;
}//end function inputData
//function outputData receives myString by value and outputs it to command line
void outputData(string bString)
{
cout << bString;
} //end function outputData