问题描述
1)说,
CString b;
char * a;
如何分配b进入一个?
strcpy(a,b)在编译时没有问题,但我没有得到我想要的东西。
2)我用过
char ** argv
从控制台获取输入,我可以返回int或char *。但是我怎么能这样做呢? (将int和char *类型的变量分配到一个字符串
**)
谢谢!
1) say,
CString b;
char * a;
how do I assign b into a ?
strcpy(a,b) has no problem in compiling but I don''t get what I want.
2) I used
char ** argv
to get input from the console and I can get back int or char * . But how can
I do the reverse ? (Assigning variables of type int and char * into a char
**)
Thanks!
推荐答案
抱歉CString不在话题。
MSDN .... CString theString(这是一个测试);
LPTSTR lpsz = new TCHAR [theString.GetLength()+ 1];
_tcscpy(lpsz,theString);
// ...根据需要修改lpsz
Sorry CString is off topic.
MSDN....CString theString( "This is a test" );
LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
_tcscpy(lpsz, theString);
//... modify lpsz as much as you want
请,我正在写一个MFC应用程序。
Please, I am writing a MFC application.
他刚给你答案,停止抱怨。
你也可以试试。
CString cstr(" Garbage" );
//在字符串中创建缓冲区的副本
char * buf = cstr.GetBuffer(cstr.GetLength());
//使用char *缓冲区后执行此操作
cstr.ReleaseBuffer();
He just gave you the answer, stop whining.
You can also try.
CString cstr("Garbage");
// Makes a copy of the buffer in the string
char* buf = cstr.GetBuffer(cstr.GetLength());
// Do this after you are done using your char* buffer
cstr.ReleaseBuffer();
这篇关于将CString分配给char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!