Solved

How to copy char* data to CString data type?

Posted on 2002-06-16
5
1,669 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
Adapt this command to show who installed 29 111
Shell script to login to remote m/c and execute commands 10 78
noX challenge 17 130
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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