gpt4 book ai didi

c++ - C++中用于搜索字符串模式的正则表达式

转载 作者:太空宇宙 更新时间:2023-11-04 15:32:58 24 4
gpt4 key购买 nike

我有这样一个字符串:

string s ="one 1 two 2 three 3";

我想写一个正则表达式,当用户输入“一”时我应该打印 1,如果输入为“二”...任何建议或帮助将不胜感激。

最佳答案

放弃正则表达式。而是写一些代码。使用某种形式的东西

int main()
{
std::map<std::string, int> m = {{"one", 1}, {"two", 2}, {"three", 3}};
std::string input;
std::cin >> input
std::cout << m[input];
}

注意奇特的初始化:从 C++11 开始有效。

关于c++ - C++中用于搜索字符串模式的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44676668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com