将CString变量传递给char变量

将CString变量传递给char变量

本文介绍了将CString变量传递给char变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我想知道我进入一个变量,假设在这个变量中CString testCStr我一步一步地得到某人的名字

我想在字符类型数组中传递此名称
就像

Hi All


I want to know that i get in a variable suppose CString testCStr in this variable i get the names of somes step by step

i want to pass this name in an array of character type
like

  char name[];

name=testCStr;// at this point it gives me error


我想将CString 变量命名为字符类型数组,并将其用于进一步的操作.

如何在CString(testCStr)的变量中传递strign.到char aray变量名称;

plz帮助


i want to name of CString variable into character type array and use it further operations.

how to transfer the strign in the variable of CString(testCStr). to the char aray variable name;

plz Help

推荐答案

const int SIZE = 256;
char name[SIZE];

strncpy(name, testCStr, SIZE-1);
name[SIZE] = '\0';


const char * name = (const char *) testCStr;

Or better,

LPCTSTR name = (LPCTSTR) testCStr;


CString testCStr;

testCStr = "This is an example.";

char * chr = new char[testCStr.GetLength()];

sprintf(chr, "%s", testCStr);


这篇关于将CString变量传递给char变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 03:55