jeudi 29 août 2019

How to use remove_if to remove only leading and trailing spaces c++ [duplicate]

This question already has an answer here:

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