Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:06:50+00:00 2026-06-10T04:06:50+00:00

This is my first time asking a question on Stackoverflow. I can’t get a

  • 0

This is my first time asking a question on Stackoverflow.

I can’t get a multidimensional vector to output the data when I use array of char and a class.

The below code outputs unexpected characters like “「” and “[B”, although I want it to print “234987 NAME MESSAGE1? 1030.”

Can anybody help me? Thanks.

#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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:06:52+00:00Added an answer on June 10, 2026 at 4:06 am

    char input[] is a local variable, what this means is that it expires at the } at the end of the constructor. All the pointers in the vector are pointing at locations to this local variable. If you change the code to static char input[] or use a global array, etc. the code should work correctly because you have now made sure that the array exists for the lifetime of the program.

    Other notes:

    • Change void main() to int main() to be a C++ conforming program.
    • I don’t see a #include <cstring> for strtok, etc.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time asking a question on stackoverflow. I'm working on a
This is my first time asking my question at stackoverflow. I'm working on a
this is my first time asking a question here. I tried to be well
this is my first time asking a question so bear with me. I am
I am new to Python and this is my first time asking a stackOverflow
First of all this is the first time I am asking a java question
First time using this service for a question. I hope I am not asking
This is my first time asking a question, please be gentle! I have a
I am first time asking question here, sorry, but I can not find similar
Hi this is the first time I am asking a question here. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.