gpt4 book ai didi

C++ 分词器分隔符不编译

转载 作者:行者123 更新时间:2023-11-30 02:44:06 25 4
gpt4 key购买 nike

我想用逗号分隔,我有以下用逗号分隔线实例化的类。类如下:

#include <sstream>
#include <stdio.h>
#include <iostream>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <vector>
#include <string>
#include <set>
#include <vector>
#include <boost/tokenizer.hpp>

class Packet {

public:
int packetEndDateTime;
int creationTimeStamp;
std::string mydatetime;
std::string micses;
std::string message_type;
std::string teid;
std::string teid_cp;
std::string teid_data;
std::string apn;
std::string msisdn;
std::string cause;
std::string causeText;
std::string responseDate;
std::string allData;
std::string fields[9];
int fieldPos = 0;

/*
boost::char_separator<char> sep(",", "|", boost::keep_empty_tokens);
typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
*/
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(",", "|", boost::keep_empty_tokens); // empty token policy

Packet(){ }

Packet(std::string inMessage){
set_message(inMessage);
}

void set_message(std::string inMessage){

allData = inMessage;

tokenizer tokens(inMessage, sep);

for ( tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter ){
fields[fieldPos] = *tok_iter;
fieldPos++;
}

mydatetime = fields[0];
message_type = fields[1];
teid = fields[2];
teid_cp = fields[3];
teid_data = fields[4];
cause = fields[5];
apn = fields[6];
msisdn = fields[7];
}

};

编译器返回:

g++ -o ggsnGiParser welcome.cc -lboost_filesystem -lboost_program_options -lboost_system  -std=c++11
In file included from welcome.cc:49:0:
Packet.hpp:39:41: error: expected identifier before ','
Packet.hpp:39:41: error: expected ‘,’ or ‘...’ before ','
Packet.hpp: In member function ‘void Packet::set_message(std::string)’:
Packet.hpp:51:40: error: no matching function for call to ‘boost::tokenizer<boost::char_separator<char> >::tokenizer(std::string&, <unresolved overloaded function type>)’
Packet.hpp:51:40: note: candidates are:
In file included from Packet.hpp:12:0,
from welcome.cc:49:
/usr/include/boost/tokenizer.hpp:62:5: note: template<class Container> boost::tokenizer::tokenizer(const Container&, const TokenizerFunc&)
/usr/include/boost/tokenizer.hpp:62:5: note: template argument deduction/substitution failed:
In file included from welcome.cc:49:0:
Packet.hpp:51:40: note: cannot convert ‘((Packet*)this)->Packet::sep’ (type ‘<unresolved overloaded function type>’) to type ‘const boost::char_separator<char>&’
In file included from Packet.hpp:12:0,
from welcome.cc:49:
/usr/include/boost/tokenizer.hpp:58:5: note: template<class Container> boost::tokenizer::tokenizer(const Container&)
/usr/include/boost/tokenizer.hpp:58:5: note: template argument deduction/substitution failed:
In file included from welcome.cc:49:0:
Packet.hpp:51:40: note: candidate expects 1 argument, 2 provided
In file included from Packet.hpp:12:0,
from welcome.cc:49:
/usr/include/boost/tokenizer.hpp:53:5: note: boost::tokenizer<TokenizerFunc, Iterator, Type>::tokenizer(Iterator, Iterator, const TokenizerFunc&) [with TokenizerFunc = boost::char_separator<char>; Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; Type = std::basic_string<char>]
/usr/include/boost/tokenizer.hpp:53:5: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >’
/usr/include/boost/tokenizer.hpp:32:9: note: boost::tokenizer<boost::char_separator<char> >::tokenizer(const boost::tokenizer<boost::char_separator<char> >&)
/usr/include/boost/tokenizer.hpp:32:9: note: candidate expects 1 argument, 2 provided
/usr/include/boost/tokenizer.hpp:32:9: note: boost::tokenizer<boost::char_separator<char> >::tokenizer(boost::tokenizer<boost::char_separator<char> >&&)
/usr/include/boost/tokenizer.hpp:32:9: note: candidate expects 1 argument, 2 provided

我真的不明白问题可能出在哪里......

非常感谢任何帮助!

大卫

最佳答案

替换

boost::char_separator<char> sep(",", "|", boost::keep_empty_tokens); // empty token policy

boost::char_separator<char> sep = {",", "|", boost::keep_empty_tokens}; // empty token policy

在类声明中构造时,您必须避免使用特定的 () 语法。

这可能隐藏了更多的错误。

关于C++ 分词器分隔符不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25604578/

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