[code]
#ifndef __CORRECT_ISO_CPP_STRING_H_PROTO
inline void*
memchr(void* __p, int __c, size_t __n)
{ return memchr(const_cast
by cookis - C/C++ - 2010-01-12 13:29:48 阅读(4475) 回复(2)
本帖最后由 gavinprogram 于 2011-01-10 13:14 编辑
#include
vc++ 环境下,关于string与cstring之间的转换问题, 如: string str = "test"; cstring cstr; cstr.Format(_T("%s"),str.c_str()); 结果cstr的值显示乱码,不是期望的"test" 请问这是怎么回事呀,string又怎么转换成cstring呢?
今天遇到一个难题,以前一直都是从TCHAR *转换到cstring,今天需要cstring 转换成TCHAR *的方法,找了一下MSDN文档,没有发现有现成的函数可以用。后来上网搜索了一下,方法还不少。如下几种: 方法一,使用强制转换。例如: cstring theString( "This is a test" ); LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString; 方法二,使用strcpy。例如: cstring theString( "This is a test" ); LPTSTR lpsz = new TCHAR[theString.GetLe...
gdb调试过程如下,为什么打印tmp时显示的总是这种东西{m_pchData = 0xd5a1b0},怎样能打印出我赋它的字符串? Breakpoint 1, CRptMgrThread::RptExec (this=0x95504c8, data=0x953acf8) at RptMgrThread.cpp:224 224 cstring tmp = _T(""); Current language: auto; currently c++ (gdb) p tmp $1 = {m_pchData = 0x9526e8c} (gdb) n 225 tmp = GetPacketString((F...
请教各位高手:能否把cstring和int相互转化.eg:cstring A={2,3,4,5,6} ;int B[];如何才能使B[]={2,3,4,5};且是整形数组.可以转化吗?急切想知道答案!谢谢各位!
一直都是用MS的开发工具,现在不得不转到 sco unix 下。搞了个把星期,才发现在 sco unix 下用 C++ 是一件很痛苦,很容易疑惑的事情。 用惯了MS 的 cstring 在 sco unix 找不到可以替代的方式,就连std::string 也没有,不得不自己定义这个类。 不知道各位大侠有没有已经定义好的这个类? 我现在自己也写了有一部分了,但因为是刚刚学会在unix 下编程,估计是写得不怎么样了,现在把代码传上来,也请高手指点。 还有,我想知道,...
C++ String: How to convert between 'cstring' and 'std::string'? 'cstring' to 'std::string': std::string cannot always construct from a LPCTSTR i.e. the code will fail for UNICODE builds. So the following conversion will lead to error: cstring cs("Hello"); std::string s((LPCTSTR)cs); As std::string can construct only from LPSTR / LPCSTR, a programmer who uses VC++ 7.x or better can utilize conver...
cstring str; str = "hello,world"; printf("%s\n",str); 这个printf语句,在windows下行正确运行; 但我一直不知道这样调用它到底调用了那一个operator的转换? 我在Linux下写cstring类时,定义了 operator char*() 和operator const char*() 两个类型转换,可是 printf("%s\n",str);这种写法编译时警告通过,但运行时出现错误. 如果写成printf("%s\n",(char*)str);一切都OK了. 想问一下,windows下是如何实现的??