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 183 views
1 answer 155 views
1 answer 142 views
1 answer 182 views
2 answers 226 views
2 answers 116 views
...