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;
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> > msgsis probably your best choice.You cannot use a variable as a type. You could have a queue of character pointers though.
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 withnewormalloc) 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::stringwould avoid all of these problems.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.