Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with insert in STL list

Posted on 2006-05-18
7
Medium Priority
?
250 Views
Last Modified: 2013-11-17
Hi!
This is the code that gives me problem

std::list<AnsiString> l_pPadres;//list with elements: "uno" "dos" "tres" "cuatro"
std::list<AnsiString> l_pHijos;//list with elements: "alfa" "beta" "delta"
//I wont insert all l_pHijos elments between elements  "dos" and "tres" of the list  l_pPadres
//Then the list l_Padres must be:: "uno" "dos" "alfa" "beta" "delta" "tres" "cuatro"

//1 step: I found where is "dos " in the list  l_pPadres
std::list<AnsiString>::iterator mi3Iterador;
for(mi3Iterador = l_pPadres.begin();mi3Iterador != l_pPadres.end();mi3Iterador++)
{//begin for mi3Iterador
if(*mi3Iterador) == AnsiString("dos"))
break;
}//end for mi3Iterador

//2 step: I put the pointer after "dos"
mi3Iterador++;

//3 step: I try to do the insertion
mi3Iterador.insert(mi3Iterador, l_pHijos.begin(), l_pHijos.end());

//4 ste: When I compiled I have the following message error:
list<AnsiString,allocator<AnsiString>>::iterator

Please, could anyone help me?
Regards
0
Comment
Question by:JulioBeta
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:cwwkie
ID: 16720855
can you post the exact error message?
0
 

Author Comment

by:JulioBeta
ID: 16724788
The exact errer message is:
list<AnsiString,allocator<AnsiString>>::iterator
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16725241
> The exact errer message is:
> list<AnsiString,allocator<AnsiString>>::iterator

I do not know any compiler which gives an error just like that.

Normally a compiler error looks like this:
    bankaccount.h(14) : error C2146: syntax error : missing ';' before identifier 'm_Name2'
0
 
LVL 2

Accepted Solution

by:
pmdw earned 2000 total points
ID: 16738343
Hi
  note you are inserting into the iterator here not the list
  mi3Iterador.insert(mi3Iterador, l_pHijos.begin(), l_pHijos.end());
  try this
 
l_pPadres.insert(mi3Iterador, l_pHijos.begin(), l_pHijos.end());


here is a fuller listing

//=============================================================
#include <list>
#include <iterator>
//=============================================================

//function starts here

   AnsiString test;  // just for checking and debugging
   std::list<AnsiString> l_pPadres;//list with elements: "uno" "dos" "tres" "cuatro"
   std::list<AnsiString> l_pHijos;//list with elements: "alfa" "beta" "delta"
  //I wont to insert all l_pHijos elments between elements  "dos" and "tres" of the list  l_pPadres
  //Then the list l_Padres must be:: "uno" "dos" "alfa" "beta" "delta" "tres" "cuatro"

  l_pPadres.push_back("uno");
  l_pPadres.push_back("dos");
  l_pPadres.push_back("tres");
  l_pPadres.push_back("cuatro");

  l_pHijos.push_back("alfa");
  l_pHijos.push_back("beta");
  l_pHijos.push_back("delta");

  //1 step: I found where is "dos " in the list  l_pPadres
  std::list<AnsiString>::iterator mi3Iterador;

  for(mi3Iterador = l_pPadres.begin();mi3Iterador != l_pPadres.end();mi3Iterador++)
  {//begin for mi3Iterador
    test = *mi3Iterador;
    if( *mi3Iterador == AnsiString("dos"))
    {
      break;
    }
  }//end for mi3Iterador
  //=============================================================
  // You might want to try this instead of the while if
  // mi3Iterador = find(l_pPadres.begin(),l_pPadres.end(),AnsiString("dos"));
  //============================================================

  //2 step: I put the pointer after "dos"
  mi3Iterador++;
  test = *mi3Iterador;
  //3 step: I try to do the insertion
  //=============================================================
  //mi3Iterador.insert(mi3Iterador, l_pHijos.begin(), l_pHijos.end());
  // note you are inserting into the iterator here not the list
  //=============================================================
  l_pPadres.insert(mi3Iterador, l_pHijos.begin(), l_pHijos.end());

  // just for checking and debugging
  for(mi3Iterador = l_pPadres.begin();mi3Iterador != l_pPadres.end();mi3Iterador++)
  {//begin for mi3Iterador
    test = *mi3Iterador;
  }//end for mi3Iterador

//function ends here



0
 

Author Comment

by:JulioBeta
ID: 16744061
Thanks.
Your answer has the solution to my problem.

Regards
JulioBeta
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

810 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