无论在 C++ 中是什么,撇号都会被解释为字符

问题描述

我遇到了问题。如果需要,这里是代码:

#include<iostream>
#include<string>
std::string findthis = "I\'m";
std::string input;
int index;
std::string sub = "Hi";
int main() {
    while (true) {
        std::getline(std::cin,input);
        if ((index = input.find(findthis)) != std::string::npos) {
            input.replace(index,2,sub);
            std::cout << input << ",I'm dad!\n";
        }
    }
}

是的,这是一个简单的老爸机器人程序,但我正在学习 C++ 中的搜索和替换。但是,如果我尝试执行代码,结果如下:

(me) I'm test
(output) Him test,I'm dad!

有什么办法可以解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)