我有点疑惑如何定义spirit :: qi规则被传递给qi :: parse(),它应该省略firts“,”出现。说,我使用以下编译代码:
std::string out_str; int out_int;
std::string s2(",345");
bool rc = qi::parse(s2.begin(), s2.end(), qi::omit[qi::lit(",")] >>
qi::int_, out_int);
但代码没有:
bool rc = qi::parse(s2.begin(), s2.end(), qi::omit[qi::lit(",")] >>
qi::as_string[*qi::digit], out_str);
发出错误:
boost\boost_1_64_0\boost\spirit\home\qi\detail\assign_to.hpp(153): error C2440: 'static_cast': cannot convert from 'const std::string' to 'char'
有人可以帮我理解我做错了吗?
答案 0 :(得分:0)
假设你真的只想解析一个整数列表,其中一些元素可能正在消失,只需拼写它就可以了:
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main() {
for (std::string const input : {"", ",", ",345", "1,,2,3,4,"}) {
std::vector<int> the_important_stuff;
bool ok = qi::parse(input.begin(), input.end(), -qi::uint_ % ',', the_important_stuff);
if (ok)
std::cout << "Input '" << input << "' parsed into " << the_important_stuff.size() << " integers\n";
else
std::cout << "Input '" << input << "' failed to parse\n";
}
}
这就是全部。并且它很好地解析为Input '' parsed into 0 integers
Input ',' parsed into 0 integers
Input ',345' parsed into 1 integers
Input '1,,2,3,4,' parsed into 4 integers
,其中T是适合您的应用程序域的适当整数类型。
bool ok = qi::phrase_parse(input.begin(), input.end(), -qi::uint_ % ',', qi::space, the_important_stuff);
打印
Dim c1 As Range
Set c1 = ActiveSheet.QueryTables(1).ResultRange
ActiveSheet.ListObjects.Add(SourceType:=xlSrcRange, Source:=c1, TableStyleName:="TableStyleLight1", XlListObjectHasHeaders:=1).Name = "Test"
太也忽略任何无关紧要的空格(即不在数字内),将调用更改为
OnChange