在Regex CPP中使用变量
using a variable in regex cpp
我有一个字符串:
string str1= "hello";
string str2="hel";
我正在这样做以查看str1是否有str2:
regex e = str2+"*"
bool x=regex_match(str1,e);
cout<<x;
我得到的:错误:从'std :: __ cxx11 :: basic_string'到非降低类型的'";
如何在我的正则使用变量。有人可以告诉我我要去哪里?tia。
查看有关 regex
template <class ST, class SA>
explicit basic_regex ( const basic_string<charT,ST,SA>& str, flag_type flags =
ECMAScript );
构造函数是显式的,因此您应该写
regex e(str2+"*");
不是
regex e = str2+"*";
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 尝试通过多个向量访问变量时,向量下标超出范围
- 试图让变量检查数组中的某些内容
- Cpp-Tuple使用带有变量的get
- 将包含C样式数组的对象初始化为成员变量(C++)
- 在Regex CPP中使用变量
- 应该如何使用C++11 Regex从存储在文本文件中的表中创建变量
- Boost regex smatch在递归函数中的行为就像一个静态变量
- 无法将boost::regex定义为私有变量
- 为什么我得到两个不同的结果,而使用sregex_iterator与regex变量模式vs构造模式