There's a reason for the STL functios
Code:
#include <iostream>
#include <string>
#define Trim(pointer1,pointer2) tTrim<string>(pointer1, pointer2)
template <typename T, typename I>
T tTrim(I i, I f)
{
T buff;
std::remove_copy_if(i, f, std::back_insert_iterator<T>(buff), std::bind2nd(std::equal_to<char>(),' '));
return buff;
}
int main()
{
using namespace std;
string str, buff;
cout << "Input a string with spaces: "; getline(cin, str);
buff = Trim(str.begin(), str.end());
cout << "The same string w/o spaces: " << buff << endl;
system("pause");
return 0;
}