I am trying to pull out the firstName string, However I'm getting very strange outputs.
Sample Data: 75428 Marston, Edward
Wanted Output: Marston Edward 75428
Output Receiving: Marston, Edwa Edward 75428
Code:
ifstream textFile("NameZip.txt");//File initializer
int counter = 0; //Used to cycle data into struct[] implementData. Avoiding a longer more memory hungry alternative since we know the file is going to be 20 lines long
int tmpZip;
string tmpString;
personData implementData[20];//creates object for structure
if(textFile.is_open())//checks to make sure file exists in same folder to avoid errors
{while(getline(textFile,tmpString))
{
stringstream convert(tmpString.substr(0,6));
convert >> tmpZip; //pulls out the Zipcode
string firstName = tmpString.substr(tmpString.find(" ") +1,tmpString.find(","));//pulls out the first name
string lastName = tmpString.substr(tmpString.find(",")+2); //pulls out last name
implementData[counter++] = {tmpZip,firstName,lastName}; //sets value for that tab in the structure personData
}}else
cout << "There was a problem reading from the textFile\nPlease make sure the file is in the same folder as the .cpp program" << endl;
printData(implementData);
return 0;
It's not just this one data to, all data for First Name seems to stop at the 13th character instead of stopping at the comma. Am I splitting the data incorrectly?