I cant seem to return str in my RemSpacePunct function.
I wanted to make a function that removes spaces in a string but when I run the code, it won't remove the space.
string RemSpacePunct(string str);
string sort(string str);
int main(){
string s = "partial men";
sort(s.begin(), s.end());
RemSpacePunct(s);
cout << s;
}
string RemSpacePunct(string str)
{
//add code here
int s, i;
s = str.length();
for(i = 0; i < s; i++){
if(isalnum(str[i]) == false){
str.erase(i, 1);
}
}
return str;
}
s = RemSpacePunct(s);RemSpacePunct(s);, you should not expect this to have any effect on the value ofswithin the function, no matter what code you write in the function body. This is because you have passed the string by value - making a copy - and are expecting to receive the changes using the return value, but you do nothing with that return value.strand don't take into account thatstrs length decreases.