之前缺少模板参数
Missing template argument before
本文关键字:参数 更新时间:2023-10-16
我正在尝试使用正则表达式获取包含在字符串中的子字符串,但似乎收到以下错误:
//code
#include <regex>
#include <iostream>
using namespace std;
int main(){
string str1="hello "trimthis" please";
regex rgx(""([^"]*)""); // will capture "trimthis"
regex_iterator current(str1.begin(), str1.end(), rgx);
regex_iterator end;
while (current != end)
cout << *current++;
return 0;
}
//错误 "当前"之前缺少模板参数
"结束"之前缺少模板参数
在此范围内未声明"当前">
是否有与我尝试执行的操作不同的语法,因为我以前没有使用过正则表达式并且是 c++ 的新手
问题 1
regex_iterator
是一个类模板。您需要使用sregex_iterator
.
问题2
*current
计算结果为std::smatch
。将此类对象插入std::ostream
没有重载。您需要使用:
cout << current->str();
这是对我有用的程序的更新版本。
//code
#include <regex>
#include <iostream>
using namespace std;
int main(){
string str1="hello "trimthis" please";
regex rgx(""([^"]*)""); // will capture "trimthis"
sregex_iterator current(str1.begin(), str1.end(), rgx);
sregex_iterator end;
while (current != end)
{
cout << current->str() << endl; // Prints the entire match "trimthis"
cout << current->str(1) << endl; // Prints the group, trimthis
current++;
}
return 0;
}
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用Luacneneneba API正确读取字符串和表参数
- 在派生函数中指定void*参数
- 视图中的参数推导失败:take_while
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- 使用指向成员的指针将成员函数作为参数传递
- 没有名称的C++模板参数
- 如何将enable-if与模板参数和参数包一起使用