#include <iostream>
#include <string>
void removeSpaces(std::string);
int main()
{
std::string inputString;
std::cout<<"Enter the string:"<<std::endl;
std::cin>>inputString;
removeSpaces(inputString);
return 0;
}
void removeSpaces(std::string str)
{
size_t position = 0;
for (position = str.find(" "); position != std::string::npos; position = str.find(" ",position))
{
str.replace(position ,1, "%20");
}
std::cout<<str<<std::endl;
}
我無法看到任何輸出。例如在C++中用%20替換字符串中的空格
Enter Input String: a b c
Output = a
怎麼了?
可能重複不能在字符串中使用? C++](http://stackoverflow.com/questions/4992229/spaces-cant-be-used-in-string-c) –