Converting int to const char*

  • ksekhon90
  • Born
  • Born
  • ksekhon90
  • Posts: 4

Post 3+ Months Ago

Hello

I am having trouble converting int to const char*.

Here is the code :

CPP Code: [ Select ]
{
std::vector<int> ids = m_gui->get_config()->ids();
 
int k =0;
   for (std::vector<int> :: const_iterator ich = ids.begin(); ich!= ids.end(); ++ich)
      {
      //cout<<(*ich);
      id_box[k]->AddEntry(*ich,0);
      k++;
      }
}
  1. {
  2. std::vector<int> ids = m_gui->get_config()->ids();
  3.  
  4. int k =0;
  5.    for (std::vector<int> :: const_iterator ich = ids.begin(); ich!= ids.end(); ++ich)
  6.       {
  7.       //cout<<(*ich);
  8.       id_box[k]->AddEntry(*ich,0);
  9.       k++;
  10.       }
  11. }


I am getting a bunch of numbers (16, 17, ...., ) = ids, and I am trying to put them into boxes with AddEntry.
Notice that when I compile everything that cout statement works and lists the ids I want.

The error I get is this :

call of overloaded ‘AddEntry(const int&, int)’ is ambiguous
/usr/local/root/include/TGListBox.h:318: note: candidates are: virtual void TGListBox::AddEntry(TGString*, Int_t) <near match>
/usr/local/root/include/TGListBox.h:319: note: virtual void TGListBox::AddEntry(const char*, Int_t) <near match>
/usr/local/root/include/TGListBox.h:320: note: virtual void TGListBox::AddEntry(TGLBEntry*, TGLayoutHints*) <near match>

==========================================

Now, I know that the error is coming because AddEntry( ) wants a 'const char*' in it and not an 'int*' .
My question is, how do I convert the int to a char ?

I have tried various things like :

CPP Code: [ Select ]
char str[10];
str=itoa(ich, str, 10);
  1. char str[10];
  2. str=itoa(ich, str, 10);


Doesnt work!

Any suggestions would be awesome!
thanks
Moderator Remark: Please make sure you put [cpp][/cpp] or [code][/code] tags around code in your post to make it easier to read. Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ksekhon90
  • Born
  • Born
  • ksekhon90
  • Posts: 4

Post 3+ Months Ago

Hahah!

Its cool! Problem solved :D
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Would you mind sharing your solution so that others in the future who have the same problem know what you did? Thanks!
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1219
  • Loc: Sydney

Post 3+ Months Ago

i wana see how you did that too :)
  • ksekhon90
  • Born
  • Born
  • ksekhon90
  • Posts: 4

Post 3+ Months Ago

Sure. Sorry in the massive delay in replying!
Essentially, I converted the int to a string like this :

CPP Code: [ Select ]
{
std::vector<int> ids = m_gui->get_config()->ids();
 
int k =0;
   for (std::vector<int> :: const_iterator ich = ids.begin(); ich!= ids.end(); ++ich)
      {
      std::stringstream ss;
      ss << k;
      id_box[k]->AddEntry(ss.str().c_str(),0);
      k++;
      }
}
 
 
  1. {
  2. std::vector<int> ids = m_gui->get_config()->ids();
  3.  
  4. int k =0;
  5.    for (std::vector<int> :: const_iterator ich = ids.begin(); ich!= ids.end(); ++ich)
  6.       {
  7.       std::stringstream ss;
  8.       ss << k;
  9.       id_box[k]->AddEntry(ss.str().c_str(),0);
  10.       k++;
  11.       }
  12. }
  13.  
  14.  

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.