Solved

How to copy char* data to CString data type?

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

How to copy char[200] data to CString ?

Thanks,
0
Comment
Question by:vgopalji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

729 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