How to remove trailing white spaces from a string in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s = "c++ c c# java python      \n    \t     ";

	while (!s.empty() && isspace(s.back())) s.pop_back();

	cout << s << endl;

	return 0;
}

/*
run:

c++ c c# java python

*/

 



answered Feb 25, 2017 by avibootz

Related questions

1 answer 179 views
1 answer 150 views
1 answer 134 views
1 answer 178 views
2 answers 218 views
2 answers 108 views
...