Link to home
Start Free TrialLog in
Avatar of carlNYC
carlNYC

asked on

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
Avatar of carlNYC
carlNYC

ASKER

Yea, i just tried with bloodshed and it worked. How can i make with VC++ though?
I tested your code in vc7.0 ,it worked fine.
Avatar of carlNYC

ASKER

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
Have you inluded the queue.h?
you could upgrade to vc.net.
Avatar of carlNYC

ASKER

i have included queue...Do i need include another library?
Avatar of carlNYC

ASKER

do i need to pay if i want to upgrade to vc.net?
yes,500$ or so.
Avatar of carlNYC

ASKER

Well then i am gonna stick with vc 6 for a while..
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;
}
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
ASKER CERTIFIED SOLUTION
Avatar of Mafalda
Mafalda

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#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
learn about...


using namespace std;

will save you hundreds of std:: 's
Avatar of carlNYC

ASKER

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..