removing a comma from my output

I need the comma in my program to be removed in my output I messaged my instructor for assistance and this is what she messaged me back:
The problem is that when you read in last – it includes the comma. So your cin.ignore needs 2 arguments, 100, \n. In this case, you don’t need the cin.ignore. Just read in first and then middle. Then use string functions to “find” the comma and create a substring from last starting at position 0 to the place before the comma. problem is that I have no idea what she is talking about in regard to the substring part her is my program with the find and substring that are not working
#include <iostream>
#include <string>
using namespace std;
char chr;
int main()
{
string last, first, middle;

cout<< "Enter in this format your Last name comma First name Middle name."<<endl; //Input full name in required format
last.find(",");
last.substr(0);
cin>>last; //receiving the input Last name
cin>>first; //receiving the input First name
cin>>middle; //receiving the input Middle name
cout<<first<<" "<<middle<<" " <<last; //Displaying the inputed information in the format First Middle Last name

cin>>chr;

return 0;
}

I have tried putting the find and substr in different place but its not working.

What am I doing wrong
I'm not sure if I understand you teachers comments either but maybe something like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string last, first, middle;

	cout<< "Enter in this format your Last name comma First name Middle name."<<endl;
	cin>>last; //receiving the input Last name 
	cin.ignore();

	cin>>first; //receiving the input First name
	cin.ignore();

	cin>>middle; //receiving the input Middle name
	cin.ignore();

	last = last.substr(0, last.length() -1);

	cout<<first<<" "<<middle<<" " <<last;

	cin.ignore();
	return 0;
}


My alternate solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string last, first, middle;

	cout<< "Enter in this format your Last name comma First name Middle name."<<endl;
	getline(cin, last, ',');

	cin>>first; 
	cin.ignore();

	cin>>middle; 
	cin.ignore();

	cout<<first<<" "<<middle<<" " <<last; 
	cin.ignore();

	return 0;
}
Your professor is saying that when someone enters, for example, input into your program like so:
"Enter in this format your Last name comma First name Middle name.
Smith, Jake X

Then your variables are the following:
last = "Smith,"
first = "Jake"
middle = "X"

Your professor says you can use the substr/find methods of string to cut out the comma part you don't want from the variable 'last'.
does my last.find look right? I am not sure what to put in the () for the last.substr because the length of the name will always be different. the way my program sits now the comma is still there and there is a 5 at he end of the middle name
Topic archived. No new replies allowed.