请实现一个函数,把字符串中的每个空格替换成“%20”,例如:we are family——》we%20are%20family.
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 int main() 5 { 6 string str; 7 getline(cin, str); 8 int len = str.size(); 9 int count = 0; 10 for (int i = 0; i < len; i++) 11 { 12 if (str[i] == ' ') 13 count++; 14 } 15 count = count * 2; 16 str.append(count, '