Stringw problem

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.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

Ok, I found a more elegant solution. Sorry, I'm kind of an Irrlicht n00b myself.

Code: Select all

core::stringw  GetCommand = EditBox->getText();

// core::string overloads operator '==', so this works correctly
if(GetCommand == L"hide node")
{
    q3node->setVisible(false);
} 
or even shorter

Code: Select all

if(core::stringw(EditBox->getText()) == L"hide node")
{
    q3node->setVisible(false);
} 
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

I use exacly this solution what you have posted above (I posted it myself at the begining and it was working, just there was a problem with 'one missing space' ..., so it should be if(GetCommand == L"hide node ") <- space after hide node).

Thanx again very very much :D
Guest

Post by Guest »

wow this is great, you have also taught me how to grab the text in an edit box, however, would the code to grab the text go in a function at the top? for when enter key is pressed, as i would like it so you would press enter, yuo can edit the editbox, and then press enter again to submit ur text (for a chat system),, if not i guess i will just leave it as click on he box type and press enter.
kamadian
Posts: 7
Joined: Mon Feb 06, 2006 11:57 pm

Post by kamadian »

hello, i have got some trouble converting a stringw to a char.

this is the code atm

Code: Select all

stringw message = chat->getText().c_str(); 
							stringw name = person->getText().c_str();
							SendData(name, message);
							stringw data = SendData(name, message);
it connects to a network code i wrote using sockets etc. and it uses char. However the main problem i get is with this...

Code: Select all

stringw message = chat->getText().c_str();
it keeps on displaying this error

Code: Select all

52 C:\dark chasis\Engine\network_chat\chat.cpp `c_str' has not been declared
what is wrong ... these are the current headers i have included

Code: Select all

#include <irrlicht.h>
#include <wchar.h>
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <string.h>
#include <irrString.h>
#include "senddata.h"
hybrid

Post by hybrid »

I think the problem is that getText() already returns a wchar_t* so no need to convert it. Just remove c_str() and you're fine. Even if getText() would return stringw the code would be better without c_str() in order to avoid too many conversions.
Does SendData take stringw as parameters? Otherwise you should convert in a different way.
kamadian
Posts: 7
Joined: Mon Feb 06, 2006 11:57 pm

Post by kamadian »

if i take the .c_str() out it sends another awkard message.

Code: Select all

55 C:\dark chasis\Engine\network_chat\chat.cpp cannot convert `irr::core::stringw' to `char*' for argument `1' to `char* SendData(char*, char*)' 

what i am basically trying to do is convert the stringw to a char string.

This is the SendData.h :P
not sure if it is right :S

Code: Select all

#ifndef _SENDDATA_H 
#define _SENDDATA_H 
 
char *SendData(char *, char *); 
 
#endif
thanks for the reply :D
hybrid

Post by hybrid »

Ok, that's good because now it reaches the SendData command. Now change all stringw to stringc and you should be done.
kamadian
Posts: 7
Joined: Mon Feb 06, 2006 11:57 pm

Post by kamadian »

that didnt work so instead my friend and i made a unicode to ascii and ascii to unicode converter.

here they are

U2A

Code: Select all

void u2a(char *st1, char *st2)
{
   int i=0;
   while( st1 [ 2*i ] )
   {
      st2[ i ] = st1[ 2*i ];
      i++;
   }
   st2[ i ] = 0;
}
A2U

Code: Select all

void a2u( char *st1, char *st2)
{
   int i=0;
   while( st1[ i ] )
   {
      st2[ 2*i ] = st1[ i ];
      st2[ 2*i + 1 ] = 0;
      i++;
   }
   st2[ 2*i ] =0;
   st2[ 2*i+1 ] = 0;
}
and here is ym code all working :D

Code: Select all

char *message = (char *)(chat->getText());
char *name = (char *)(person->getText());
u2a(name, name_ascii);
u2a(message, message_ascii);
SendData(name_ascii, message_ascii);
FILE *out=fopen("log.txt","wb");
fwrite(name, 10,1,out);
fclose(out);
char *data, data_unicode[4096];;
data = SendData(name_ascii, message_ascii);
a2u(data, data_unicode);
chatwindow->addItem((wchar_t *)data_unicode);
chat->setText(L"");
however one problem i do have, it returns a load fo squares etc. before and after the message >.<

also the txt file is mostly for error handelling.
kamadian
Posts: 7
Joined: Mon Feb 06, 2006 11:57 pm

Post by kamadian »

probably going way of topic now, but heck, i have a wierd problem :P

Code: Select all

212 C:\dark chasis\Engine\network_chat2\chat.cpp invalid conversion from `int' to `int*' 
Post Reply