| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 892 人关注过本帖
标题:关于CString转换char*的问题?
只看楼主 加入收藏
lmx8362655
Rank: 1
等 级:新手上路
帖 子:4
专家分:7
注 册:2007-5-28
收藏
 问题点数:0 回复次数:1 
关于CString转换char*的问题?
我写了俩段小测试程序,关于CString强制转换CHAR*的试验,如下:
#include "iostream.h"
#include "afx.h"

void main()
{
    CString  str="16 00 00 00 02 02 00 00";
    char * str1;
    CString tempstr;
    tempstr=str.Left(5);
    str1=(char*)(LPTSTR)(LPCTSTR)(tempstr);
    cout<<str1<<endl;
   
}

#include "iostream.h"
#include "afx.h"

void main()
{
    CString  str="16 00 00 00 02 02 00 00";
    str.Remove(' ');
    char * str1;
 
    str1=(char*)(LPTSTR)(LPCTSTR)(str.Left(5));
    cout<<str1<<endl;
   
}

为什么上面那段能得到最终结果,下面这段确是乱码!
搜索更多相关主题的帖子: CString char 
2010-05-13 20:23
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:0 
转完后 记得加上'\0'
2010-05-13 21:34
快速回复:关于CString转换char*的问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022927 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved