Stackoverflow で質問するのはこれが初めてです。
char の配列とクラスを使用すると、データを出力するための多次元ベクトルを取得できません。
以下のコードは、「234987 NAME MESSAGE1? 1030」を出力したいのですが、「「」や「[B」などの予期しない文字を出力します。
誰でも私を助けることができますか?ありがとう。
#include <iostream>
#include <vector>
using namespace std;
class test{
public:
test();
void output();
private:
std::vector< std::vector<char*>> Message_detail;
};
test::test(){
int i = 0;
int j = 0;
char input[] ="USERID=234987+USERNAME=NAME+MESSAGE=MESSAGE1?+TIME=1030&USERID=12304234+USERNAME=NAME2UKI+MESSAGE=HIII+TIME=1330&USERID=1376321+USERNAME=JONES12+MESSAGE=GENKI DAYO+TIME=1025";
char * pch;
pch = strtok (input,"+=&");
Message_detail.push_back( vector<char*>() );
while (pch != NULL)
{
if((int)Message_detail[j].size() == 4){
Message_detail.push_back( vector<char*>() );
j++;
}
if(strlen(pch) < 1){
Message_detail.pop_back();
}
if(i % 2 != 0){
Message_detail[j].push_back(pch);
}
i++;
pch = strtok (NULL, "+=&");
}
}
void test::output(){
for(vector<char*>::size_type i = 0; i < Message_detail.size(); i++){
for(vector<char*>::size_type j = 0; j < Message_detail[i].size(); j++){
std::cout << Message_detail[i][j] << endl;
}
}
}
void main(){
test hello;
hello.output();
}