This question already has an answer here:
- What's the best way to trim std::string? 40 answers
I'm trying to remove the leading and trailing spaces only from a string read by getline.
i.e: " John Smith ".
I used emp_name.erase(remove_if(..) Could it be used without removing the space between words?
cout << "\nEnter Employee First and Last Name: ";
cin.ignore();
getline(cin, emp_name);
emp_name.erase(remove_if(emp_name.begin(), emp_name.end(), ::isspace), emp_name.end());
I'm trying to get "John Smith"
Aucun commentaire:
Enregistrer un commentaire