?
Solved

easy question!!!

Posted on 2003-03-26
14
Medium Priority
?
249 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:carlNYC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 

Author Comment

by:carlNYC
ID: 8215701
Yea, i just tried with bloodshed and it worked. How can i make with VC++ though?
0
 
LVL 1

Expert Comment

by:beavis_shenzhen
ID: 8215873
I tested your code in vc7.0 ,it worked fine.
0
 

Author Comment

by:carlNYC
ID: 8215936
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:beavis_shenzhen
ID: 8216030
Have you inluded the queue.h?
you could upgrade to vc.net.
0
 

Author Comment

by:carlNYC
ID: 8216274
i have included queue...Do i need include another library?
0
 

Author Comment

by:carlNYC
ID: 8216276
do i need to pay if i want to upgrade to vc.net?
0
 
LVL 1

Expert Comment

by:beavis_shenzhen
ID: 8216375
yes,500$ or so.
0
 

Author Comment

by:carlNYC
ID: 8216416
Well then i am gonna stick with vc 6 for a while..
0
 
LVL 10

Expert Comment

by:substand
ID: 8216586
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
 
LVL 12

Expert Comment

by:Salte
ID: 8216614
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
 
LVL 6

Accepted Solution

by:
Mafalda earned 100 total points
ID: 8216938
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
 

Expert Comment

by:Squall_Leonheart
ID: 8218543
#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
 
LVL 7

Expert Comment

by:a1programmer
ID: 8219954
learn about...


using namespace std;

will save you hundreds of std:: 's
0
 

Author Comment

by:carlNYC
ID: 8222877
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question