• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1720
  • Last Modified:

How to copy char* data to CString data type?

Hi All,

How to copy char[200] data to CString ?

Thanks,
0
vgopalji
Asked:
vgopalji
1 Solution
 
migelCommented:
Hi!
char sz[200] = "Hi!";
CString str;
str = sz;
or your char array contains zeros?
0
 
joakimfCommented:
Or you can do it in the constuctor:
char sz[200] = "Hi!";
CString str ( sz );

Just one less line :)

/Joakim
0
 
muneeb_baigCommented:
Or you can also use the Format method fo CString. that would help u, if u wanna concat other string too:
char sz[200] = "xyz";
CString str;
str.Format("%s", sz);//would copy the contents of sz to str

//or to concat other string
str.Format("Other String and my data = %s", str);
0
 
snoeglerCommented:
>> str.Format("%s", sz);

IMHO this is pretty bloated (and slow) for this task.
"str = sz;" does the job much faster, as pointed out by migel.
0
 
snoeglerCommented:
Hm. You should've given the points to migel :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now