将数据从wchar *复制到cstring [英] copying data from wchar * to cstring
本文介绍了将数据从wchar *复制到cstring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将wchar *中的内容安全地复制到cstring.
wchar * buff =(wchar *)malloc(500);
cstring cbuff;
I want to know how to copy content from wchar * to cstring safely.
wchar *buff=(wchar*)malloc(500);
cstring cbuff;
How do I copy contents of buff into cbuff so that I can destroy buff?
推荐答案
cstring cbuff;
if(buff && (buff[0] != 0 ))
{
cbuff = cstring(buff);
}
问候
Espen Harlinn
Regards
Espen Harlinn
您尝试过以下方法吗:
Did you try this:
cbuff = (LPCWSTR)buff;
实际上我是在使用heapalloc分配内存的. 该程序导致访问冲突崩溃
但是可以使用malloc和free
Espen Harlinn和john我以两种方式尝试了..works(如果使用了malloc),并且崩溃了,如果使用了heapalloc
actually i m allocating memory with heapalloc
the program crashes access violation
but works if used malloc and free
Espen Harlinn and john i tried in both ways ..works if used malloc and crashes if used heapalloc
WCHAR *buff=(WCHAR*)HeapAlloc(GetProcessHeap(),0,100);
// WCHAR *buff=(WCHAR*)malloc(100);
wcscpy(buff,L"rajesh");
CString cbuff;
cbuff=CString(buff);
// free(buff);
HeapDestroy(buff);
这篇关于将数据从wchar *复制到cstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文