1
쉼표로 구분하고 싶습니다. 쉼표로 구분 된 행으로 인스턴스화 된 다음 클래스가 있습니다. 컴파일러와 함께 다시오고C++ 토큰 화 구분 기호가 컴파일되지 않습니다.
#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
그리고 문제가있을 수 있습니다 어디 정말 이해가 안 ...
를 어떤 도움이 크게되는 다음과 같이 클래스입니다 고맙다! 데이비드
그것은 C++ 11 기능이므로 -std = C++ 11이면 충분합니다. (물론 'sep'에 대한'{}'이니셜 라이저) –
@antonsavin 아는 느린 표준화 컴파일러로 개발하기에 적합합니다. ! – Yakk