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

  • SEARCH
  • Home
  • 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 6908045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:40+00:00 2026-05-27T08:30:40+00:00

include <queue> using namespace std; char msg[1000]; Now, I want to have a queue

  • 0
include <queue>
using namespace std;
char msg[1000];

Now, I want to have a queue that can store 5 of this kind of msg. So, it is a queue of size 5 that contains 5 arrays of characters, each array can contain up to 1000 chars.

How can I initiate the queue? I tried this but it did not work.

char msg[1000];
queue<msg> p;
  • 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-27T08:30:41+00:00Added an answer on May 27, 2026 at 8:30 am

    Edit: std::vector may be better choice, just reread you question and saw the size of the character array. If you are using it to store binary data, a std::queue< std::vector <char> > msgs is probably your best choice.

    You cannot use a variable as a type. You could have a queue of character pointers though.

    #include <iostream>
    #include <queue>
    
    std::queue <char*> msgs;
    
    int main()
    {
        char one[50]="Hello";
        msgs.push(one);
        char two[50]="World\n\n";
        msgs.push(two);
    
        msgs.push("This works two even though it is a const character array, you should not modify it when you pop it though.");
    
    
        while(!msgs.empty())
        {
            std::cout << msgs.front();
            msgs.pop();
        }
    
    return 1;
    }
    

    You could also just use std::string and avoid mistakes. If you use a char* you want a function to add msgs to queue, they cannot be on the stack (ie you would need to create them with new or malloc) than you would have to remember to delete them when you processed the queue. There would be no easy way to determine if one is in global space, one is on the stack, or one was made with new. Would lead to undefined behavior or memory leaks when not handled correct. std::string would avoid all of these problems.

    #include <iostream>
    #include <queue>
    #include <string>
    
    std::queue <std::string> msgs;
    
    int main()
    {
    
        msgs.push("Hello");
        msgs.push("World");
    
        while(!msgs.empty())
        {
            std::cout << msgs.front();
            msgs.pop();
        }
    
    return 1;
    }
    

    If it is just 5 Standard messages, then const char* would be a decent choice, but if they are always the same messages, you should consider a queue of integers that refer to the message you want. This way you could associate more actions with it. But than you could also consider a queue of objects.

    #include <iostream>
    #include <queue>
    
    std::queue <int> msgs;
    
    int main()
    {
    
        msgs.push(1);
        msgs.push(2);
    
        while(!msgs.empty())
        {
            switch(msgs.front())
            {
            case 1:
                std::cout << "Hello";
            break;
            case 2:
                std::cout << "World";
            break;
            default:
                std::cout << "Unkown Message";
            }
    
            msgs.pop();
        }
    
        return 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <queue> using namespace std; struct Call { Call( int callNum, long
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
I have the following class: #include <string> #include <stack> #include <queue> #include map.h using
i have seen in internet following DFS algorithm #include<iostream> #include<queue> #define MAX 100 using
I have a small program that uses trying to use #include <queue> . I
This is a concurrent queue I wrote which I plan on using in a
I have created MutexCondition class like this /*MutexCondtion.h file*/ #ifndef MUTEXCONDITION_H_ #define MUTEXCONDITION_H_ #include
I made this implementation for this problem : http://www.spoj.pl/problems/SHOP/ #include<iostream> #include<stdio.h> #include<queue> #include<conio.h> #include<string.h>

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.