![]() |
【转帖】convertig odstring to cstring
convertig odstring to cstring
convertig odstring to cstring hi i´m developing an application for pocket pc based in your odamfcappce example. i'm trying to create a new layer, getting the new name in a cstring and i don´t know how to transform it to odstring, to call player->setname(); in odamfcapp exmple for vc6 possible to set a odstring value directly with a cstring value (odstring var. = cstring var.), but in evc i get this error: error c2679: binary '=' : no operator defined which takes a right-hand operand of type 'class cstring' (or there is no acceptable conversion) i tried to do odstring aux((const char*)(lpctstr)layername); but i can only get the first char of the name... any help would be very much apreciatted pedro tenreiro this should work: odstring ods; cstring cs; ... ods = (lpctstr)cs; cs = (lpctstr)ods; regards chudomir quote: originally posted by donelodes i tried to do odstring aux((const char*)(lpctstr)layername); but i can only get the first char of the name... i guess you get a name as unicode (or multibyte character set) string. that's why you have a first char of a name only using odstring() constructor. i think you need to convert a string from unicode before following using. misha kuzinets chudo: your solution didn't work, i think misha kuzinets is right. this is what i'm doing: //convert from cstring to odstring odstring cdialogvistas::getodstring(cstring str){ int max = str.getlength(); char *aux = new char[max+1]; for (int i = 0 ; i < max ; i++){ aux[i] = str[i]; } aux[i] = '\0'; odstring od_aux(aux); return od_aux; } //convert from odstring to cstring cstring cdialogvistas::getcstring(odstring str){ int max = str.getlength(); char *aux = new char[max+1]; for (int i = 0 ; i < max ; i++){ aux[i] = str[i]; } aux[i] = '\0'; cstring cs_aux(aux); return cs_aux; } it's probably not the best solution and it has a warning when a convert from odstring to cstring ("conversion from 'unsigned short' to 'char', possible loss of data"), but it is working! thanks for your help pedro tenreiro did you try using the odstring::c_str() method? here is an example: code: odstring ods = "hello"; cstring cstr = ods.c_str(); i've used this quite a bit in my code, and it seems to work fine. cheers, bob |
所有的时间均为北京时间。 现在的时间是 07:22 PM. |