Solved

How to copy char* data to CString data type?

Posted on 2002-06-16
5
1,639 Views
Last Modified: 2013-11-20
Hi All,

How to copy char[200] data to CString ?

Thanks,
0
Comment
Question by:vgopalji
5 Comments
 
LVL 12

Expert Comment

by:migel
ID: 7083090
Hi!
char sz[200] = "Hi!";
CString str;
str = sz;
or your char array contains zeros?
0
 
LVL 1

Expert Comment

by:joakimf
ID: 7083212
Or you can do it in the constuctor:
char sz[200] = "Hi!";
CString str ( sz );

Just one less line :)

/Joakim
0
 

Expert Comment

by:muneeb_baig
ID: 7087868
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
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 7092031
>> 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
 
LVL 6

Expert Comment

by:snoegler
ID: 7117072
Hm. You should've given the points to migel :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now