C++ little programming question
Hello, I am trying to figure out a way to remove whitespace inside a string. Can anyone help me a little on this.
Example: input:ha ha ha
output:hahaha
I manage to only remove one space inside a string
like: input:ha ha ha
output:hahaha
Following are the code I have gotten so far:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
int i = 0;
int space_appearance = 0;
getline(cin, input, '\n');
for(i = input.find(" ", 0); i !=(int)string::npos; i=input.find(" ", i))
{
input.erase(i, 1);
space_appearance++;
i++;
}
cout << input << endl;
cout << space_appearance << endl;
}
I would really appreciate for anyhelp, thank you very much!
|