我是想把字符串内容修改为‘xx’,但是在只能修改形参的内容无法修改实参的内容,请问replaceSpace这个函数该如何修改才能在main函数调用后把它的字符串修改为‘xx’,谢谢。
class Solution {
public:
void replaceSpace(char *str,int length) {
char s[2] = {0};
s[0] = 'x';
s[1] = 'x';
s[2] = '\0';
str = s;
std::cout << str << std::endl;
}
};
int main()
{
Solution sol;
char *s = "ss";
sol.replaceSpace(s, 2);
std::cout << s << std::endl;
return 0;
}