remove spaces from string

Hi all, I need to compare strings but without taking spaces into consideration, so I need to trim my string of spaces (how ever many may there be)

I tried remove_if or just remove, but it didn't go well. Most likely I'm not using it right. Any ideas?

1
2
3
4
for (int i = 0; i <= str.length() - 1; i++)
remove_if( str.at(0),str.length(), isspace(str.at(i));

cout << "\n\n\tNew string: " << str << "\n\n";
This is ok:

1
2
3
4
	string str = "string with    spaces ";
	str.erase(remove_if(str.begin(), str.end(), ::isspace), str.end());

	cout << "String without spaces: " << str << endl;
Last edited on
thanks allot, work perfectly...
Topic archived. No new replies allowed.