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 7446755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:23:57+00:00 2026-05-29T12:23:57+00:00

I am trying to build a messageQueue based around this messageStruct struct MessageStruct{ public:

  • 0

I am trying to build a messageQueue based around this messageStruct

struct MessageStruct{
    public: std::string msg;     // what is the msg
    public: int prior;           // how important is this msg
};

That lies in a MessageQueue that is needed to act like a vector/priorityQueue (self made version that is working fine), but I put a bunch of stuff on it, like so.

int size = 20;
// constructor takes number of entries to start with
MessageQueue * queue = new MessageQueue(size);
// used as a transport mechanism
MessageStruct * msg = new MessageStruct();
msg->prior = 0;
msg->msg = "queue exists";
queue->getMsg(msg);
// increasing size does not cause memory issue,
//  use for example of dynamic size.
... other stuff is happening
size *= 2;
for (int ii = 0; ii < size; ii++){
    msg->prior = 0;
    msg->msg = "creating thing " + ii;
    // puts this message in the queue,
    //  and increases queue size if needed
    queue->getMsg(msg);
}
... // other stuff is happening
msg->prior = 10;
msg->msg = "program terminated correctly";
queue->queueDump();
delete msg;
msg = 0;
delete queue;
queue = 0;

This code gets no errors, and all memory is being released without issue, though the output of this looks like this (I generate the output in xml for sanity):

<message> 
    <index>0</index>
    <msg>program terminated correctly</msg>
    <priority>10</priority>
</message>
<message> 
    <index>1</index>
    <msg>init(). queue exists</msg>
    <priority>0</priority>
</message>
<message> 
    <index>2</index>
    <msg>reating thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>3</index>
    <msg>eating thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>4</index>
    <msg>ating thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>5</index>
    <msg>ting thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>6</index>
    <msg>ing thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>7</index>
    <msg>ng thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>8</index>
    <msg>g thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>9</index>
    <msg> thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>10</index>
    <msg>thing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>11</index>
    <msg>hing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>12</index>
    <msg>ing </msg>
    <priority>0</priority>
</message>
<message> 
    <index>13</index>
    <msg>ng </msg>
    <priority>0</priority>
</message>
<message> 
    <index>14</index>
    <msg>g </msg>
    <priority>0</priority>
</message>
<message> 
    <index>15</index>
    <msg> </msg>
    <priority>0</priority>
</message>

It looks like the strings are being generated and placed, but why are leading characters being removed?

  • 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-05-29T12:23:59+00:00Added an answer on May 29, 2026 at 12:23 pm

    needed to introduce a method to the code that converted an int to a string

    //----------
    // attempts to convert a int to a string
    //----------
    string toString(int value) {   // may need to specify std::
        string result = "";
        bool negative = false;
        if ( value < 0 ) {
            negative = true;
            value *= (-1);
        }
        do {
            string tmpstr = "0";
            tmpstr[0] += value%10;
            result = tmpstr + result;
            value /= 10;
        } while ( value != 0);
        if ( negative ) {
            result = "-" + result;
        }
        return result;
    }
    

    then modify the line

    msg->msg = "creating thing " + ii;
    

    to be

    msg->msg = "creating thing " + toString(ii);
    

    this can be costly to do in repetition, but the only other option is likely to call a string builder that doesn’t really save anything

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
Trying to build a plugin effect that will some what look better than this
Im trying to build a form that calculates a total price based on a
Trying to build a linq query based on parameters a user selects (reporting) but
I'm brand new to this and I'm trying build a simple layout of divs.
Trying to build a shopping cart based on the Agile Web Development 4th edition.
I am trying to build an HtmlHelper extension in ASP.NET MVC RC2. This code
iam trying to build a multidimensional array. public function saveRateTemplateData($RateTemplateInfo) { $RateTemplateID = $RateTemplateInfo['id'];
Im trying to build a string to call a script with args, and one
I'm trying build a method which returns the shortest path from one node to

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.