请实现—个函数,把字符串s中的每个空格替换成”%20""。
示例1:
输入:s = "we are happy ."输出:""Me%20are%20happy ."
#define _CRT_SECURE_NO_WARNINGS //vs2017下使用strcpy
#include <iostream>
#include <string>#include <stdio.h>using namespace std;void replaceSpace(string& tempStr)
{char tempBuf[100] = { 0 };strcpy(tempBuf, tempStr.c_str());cout << tempBuf << endl;tempStr.clear();for (int i = 0; i < strlen(tempBuf); ++i){if (tempBuf[i] == ' '){tempStr.append("%20");}else{tempStr.push_back(tempBuf[i]);}}
}int main()
{string tempStr = "we are happy";replaceSpace(tempStr);cout << tempStr << endl;
}



![[字符串]替换空格](https://img-blog.csdnimg.cn/490fdf4bce1c4744ade62df836bb736e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQWxzb25fQ29kZQ==,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)















