inserting list elements into another list

inset list elements into another list

Page 1 of 1

2 Replies - 525 Views - Last Post: 27 July 2009 - 04:26 PM Rate Topic: -----

#1 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

inserting list elements into another list

Posted 27 July 2009 - 03:57 PM

Hi there,
I have two lists and what I want to do is to insert some of the elements in the middle of one of the lists into another.
Does anyone have any ideas why this piece of code does not compile?

if on Line 13, I use comNode.bgin() instead of comNode.begin()+1 the coude compiles perfectly though.

Thank you for your help!

#include<iostream>
#include<list>
using namespace std;
int main()
{
	list<int> comNode;
	list<int> erased;
	comNode.push_front(10);
	comNode.push_front(100);
	comNode.push_front(1000);
	comNode.push_front(10000);
	erased.insert (erased.end (), 
					   comNode.begin()+1, 
							   comNode.end ());

	std::list <int>::const_iterator listLocator;

	for (listLocator = erased.begin(); 
				   listLocator!=erased.end(); 
									   listLocator++)
		cout <<	*listLocator << endl;

	return 0;
}



This post has been edited by machoolah: 27 July 2009 - 04:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: inserting list elements into another list

#2 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: inserting list elements into another list

Posted 27 July 2009 - 04:21 PM

It would help if you posted the error messages...
Was This Post Helpful? 0
  • +
  • -

#3 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

Re: inserting list elements into another list

Posted 27 July 2009 - 04:26 PM

the error I get is somehow above my head to understand. But I can guess that the problem is with the line where it tries to insert into the list "erased".

On Line 13 (excluding the empty lines):
if I use comNode.begin() instead of comNode.begin()+1 it would compile successfully.

does that help any?
Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1