Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you have a queue of array type?

Status
Not open for further replies.

Cirilia

Programmer
Mar 10, 2003
16
US
Is it possible to have a queue made up of something like this:

string a[20];

If so, how would you declare the queue, and how would you enQ and deQ things in the array.
 
Well I guess what I'm really trying to do is reading information from a string array into the queue. But I am having problems with this.
 
For example:

string a[20];

The array has values such as:

red
orange
yellow
green
blue .... and so on

How would declare a queue of this type, and read these values into it.
 
>> How would declare a queue of this type, and read these
>> values into it.

There are many ways to do that, here is one:
Code:
char* str[] = {"hello", "world"};
int main()
{
	queue<char*> q;
	q.push( str[0]);
	q.push( str[1]);

	while( !q.empty()){
		cout << q.front() << endl;
		q.pop();
	}
does that help?
-pete
 
That does help somewhat, but that is for characters, not strings. I'm having a problem with using a string for the queue. Is there a way to do that?
 
Ok I did replace the char* with string, but when I declare a queue:

Queue<string> Q;

I get 4 of these errors:

warning C4786: 'std::reverse_bidirectional_iterator<std::list<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<
char> > > >::iterator,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifi
er was truncated to '255' characters in the debug information
 
I get 4 of these errors:

warning C4786:

You didn't get any errors you got warnings. Use this to disable the warning messages:

Code:
#pragma warning ( disable : 4786)
#include <string>

-pete
 
That #pragma disable coding did not work to get rid of the warnings. I already have the <string> in the program however.
 
What is your question? As palbano stated, you only have warnings which will not prevent a clean compile. The #pragma will get rid of the warnings if you put it in the right place.
 
I put the #pragma coding right underneath the rest of my #include files, is this the wrong place?
 
Cirilia, under it, over it? What are you doing?

I can move that #pragma statment and compile that file about 5 times before a single Tek-Tips page loads. Why are you asking us something like that? &quot;just do it&quot;.

Plus what Federal02 said. It's not an error anyway, so... does your program work now?

-pete
 
Well like I said earlier, when I put that code into my program it did not remove the warnings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top