c++字符串:有没有好的方法来替换字符串中的字符
我想将字符串中出现的所有 ' 替换为 ^,但我看到 string.replace 不是适合我的函数,我需要编写自己的函数吗?很无聊。
I want to replace all the occurances of ' in a string to ^, but i saw string.replace is not the right function for me, do I need to write my own? It's boring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用而不是使用
std::replace
中的std::replace
>
中的string::replace
示例代码
输出:
I,am,a,string< /代码>
You can use
std::replace
from<algorithm>
instead of usingstring::replace
from<string>
Sample code
Output :
I,am,a,string