几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-04, 06:13 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】ambiguous call to overload functions in odstring.h yang686526 DirectDWG 0 2009-05-04 03:56 PM
【转帖】如何在cstring与int型之间转换 yang686526 ObjectARX(C++) 0 2009-04-16 11:07 PM
【转帖】请问怎么样把一个CString类型的变量转换成BYTE类型,逆向的呢? huangyhg vc编程 1 2009-03-25 12:39 AM
BSTR、char*和CString转换 yogy vc编程 0 2007-05-21 01:13 PM
关于Cstring 类 huangyhg vc编程 0 2007-04-28 02:59 PM


所有的时间均为北京时间。 现在的时间是 03:19 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多