Type Conversion Error

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Type Conversion Error

Post by rtr_18 »

Hi!
I got the following error while adding an item to a Combobox.

error C2664: 'irr::gui::IGUIComboBox::addItem' : cannot convert parameter 1 from 'irr::core::stringc' to 'const wchar_t *'

Code: Select all


 irr::core::array<irr::core::stringc> ctyLst = SQLdb.Query("Select DISTINCT Team from Test");
 for(int i =0; i < ctyLst.size(); i++ )
 {
    m_pCountryCbo->addItem(ctyLst[i]);
 }
How to convert 'irr::core::stringc' to 'const wchar_t *'?
bart
Posts: 2
Joined: Mon Jul 05, 2010 8:24 pm

Post by bart »

Hi

I am not sure this is the fastest method but it works. First convert it to stringw and then use c_str()

Code: Select all

m_pCountryCbo->addItem(stringw(ctyLst[i]).c_str()); 
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Basically there's two types of strings - standard and wide. Normal strings are the ones you are probably used to working with (i.e. "Hello World!"). Wide strings use two bytes per character instead of just one and use the type wchar_t instead of char. They can support many other characters, such as unicode characters, etc. You can create a wide string by simply putting an L in front of the string (i.e. L"Hello World!"). Like bart suggested, Irrlicht has a string class for each (stringc for standard strings and stringw for wide ones) and can use them to convert between the two.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

slavik262 wrote:Wide strings use two bytes per character instead of just one and use the type wchar_t instead of char.
Not necessarily. The size of a wchar_t is platform dependent. For example, it is 4 bytes on recent versions of g++ on linux.

Code: Select all

[vitek@junta pointer]$ cat t.cpp
#include <stdio.h>

int main ()
{
  printf ("sizeof(wchar_t) = %u\n", sizeof(wchar_t));
  return 0;
}
[vitek@junta pointer]$ g++ t.cpp && ./a.out
sizeof(wchar_t) = 4
slavik262 wrote:Like bart suggested, Irrlicht has a string class for each (stringc for standard strings and stringw for wide ones) and can use them to convert between the two.
I'm fairly certain that the Irrlicht string template is only good for translating strings that are representable in ASCII (i.e., the char value has to be between CHAR_MIN and CHAR_MAX).

Travis
Post Reply