easy question!!!

I have to use STL queue poniter based..
int main()
{
     list<int>myList;
     list<int>::iterator i=myList.begin();
     for(int j=1;j<5;j++)
     {
          i=myList.insert(i,j);
          i++;
     }

     i=myList.begin();
     while(i!=myList.end())
     {
          cout<<*i<<" ";
          i++;
     }

     queue <int, list<int> > myQueue(myList); //This line does not work
     return 0;
}

I am using VC++ 6.0..and something is wrong with the compiler( i think so)..any way is there a way to create a pointer based queue and STL?
Thanks..
Carl
carlNYCAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MafaldaConnect With a Mentor Commented:
The following syntax corrections solves all the apparent problems of your code in VC++ 6.0 SP5

#include <iostream>
#include <list>
#include <queue>

// the following 3 lines are not a fixes but a better way to use the std namespace as usually you will be using your own namespace so using the whole namespace would be inadequate

using std::list;
using std::queue;
using std::cout;

int main()
{
   list<int> myList;
   std::list<int>::iterator i=myList.begin(); // first fix add std::
   for(int j=1;j<5;j++)
   {
        i=myList.insert(i,j);
        i++;
   }

   i=myList.begin();
   while(i!=myList.end())
   {
        cout<<*i<<" ";
        i++;
   }

   cout << std::endl;
   std::queue <int, std::list<int> > myQueue(myList.get_allocator()); // second fix use an allocator
   return 0;
}
0
 
carlNYCAuthor Commented:
Yea, i just tried with bloodshed and it worked. How can i make with VC++ though?
0
 
beavis_shenzhenCommented:
I tested your code in vc7.0 ,it worked fine.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
carlNYCAuthor Commented:
then, something must be wrong with vc6.0..I really hate microsoft sometimes....Since , i dont have other option, is there a way to do the same thing but in vc6.0..Or perhaps , if you know where i could upgrade my VC++6..
Thanks
0
 
beavis_shenzhenCommented:
Have you inluded the queue.h?
you could upgrade to vc.net.
0
 
carlNYCAuthor Commented:
i have included queue...Do i need include another library?
0
 
carlNYCAuthor Commented:
do i need to pay if i want to upgrade to vc.net?
0
 
beavis_shenzhenCommented:
yes,500$ or so.
0
 
carlNYCAuthor Commented:
Well then i am gonna stick with vc 6 for a while..
0
 
substandCommented:
I'm not sure if there are logical errors, but this code worked in my microsoft vc++:

(you have to name the file with a .cpp extension)

#include <iostream>
#include <list>
#include <queue>



int main()
{
    list<int>myList;
    list<int>::iterator i=myList.begin();
    for(int j=1;j<5;j++)
    {
         i=myList.insert(i,j);
         i++;
    }

    i=myList.begin();
    while(i!=myList.end())
    {
         cout<<*i<<" ";
         i++;
    }

    queue <int, list<int> > myQueue(myList); //This line does not work
    return 0;
}
0
 
SalteCommented:
You could try gcc - it's free and doesn't cost anything.

Just install cygwin and you get not only a compiler but a bunch of useful tools etc.

Alf
0
 
Squall_LeonheartCommented:
#include <list>
#include <queue>
#include <iostream>
int main()
{
     std::list<int> myList;
        for(int j=1;j<5;++j)myList.push_back(j);

     std::list<int>::iterator i=myList.begin();
     for(;i!=myList.end();++i)std::cout << *i<< " ";

     std::queue <int, std::list<int> > myQueue(myList);
       
        std::cout << "\n";
     return 0;
}

this works
0
 
a1programmerCommented:
learn about...


using namespace std;

will save you hundreds of std:: 's
0
 
carlNYCAuthor Commented:
thanks all of you,
I tested your programs and the one that worked on my compilor was Mafalda's. And the reason is that Mafalda used myList.get_allocator()); which i think was the key..
Thanks again..
0
All Courses

From novice to tech pro — start learning today.