gpt4 book ai didi

c++ - boost spirit 提取第一个词并将其存储在 vector 中

转载 作者:太空狗 更新时间:2023-10-29 20:32:54 26 4
gpt4 key购买 nike

我在使用 Boost.Spirit 解析字符串时遇到问题。

字符串看起来像

name1 has this and that.\n 
name 2 has this and that.\n
na me has this and that.\n

我必须提取名称。文本“有这个和那个”始终相同,但名称可以包含空格,因此我不能使用 graph_p。

1) 如何解析这样的字符串?

由于字符串有几行这种格式,我必须将名称存储在一个 vector 中。

我用了类似的东西

std::string name;
rule<> r = *graph_p[append(name)];

为了保存一个名字但是

2) 在 vector 中保存多个名称的最佳方法是什么?

提前致谢

康拉德

最佳答案

我认为这会成功:

vector<string> names;
string name;
parse(str,
*(
(*(anychar_p - "has this and that.")) [assign_a(name)]
>> "has this and that.\n") [push_back_a(names, name)]
))

关于c++ - boost spirit 提取第一个词并将其存储在 vector 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/365427/

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