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
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
I tested your code in vc7.0 ,it worked fine.
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
Thanks
Have you inluded the queue.h?
you could upgrade to vc.net.
you could upgrade to vc.net.
ASKER
i have included queue...Do i need include another library?
ASKER
do i need to pay if i want to upgrade to vc.net?
yes,500$ or so.
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 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
Just install cygwin and you get not only a compiler but a bunch of useful tools etc.
Alf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#include <list>
#include <queue>
#include <iostream>
int main()
{
std::list<int> myList;
for(int j=1;j<5;++j)myList.push_ba ck(j);
std::list<int>::iterator i=myList.begin();
for(;i!=myList.end();++i)s td::cout << *i<< " ";
std::queue <int, std::list<int> > myQueue(myList);
std::cout << "\n";
return 0;
}
this works
#include <queue>
#include <iostream>
int main()
{
std::list<int> myList;
for(int j=1;j<5;++j)myList.push_ba
std::list<int>::iterator i=myList.begin();
for(;i!=myList.end();++i)s
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
using namespace std;
will save you hundreds of std:: 's
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..
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..
ASKER