Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4717
  • Last Modified:

char to CString

How can I convert a array of chars to a CString?
for example:
char* buf[50]
CString myString;

myString = myString + charTostr(buf);
0
el_rooky
Asked:
el_rooky
1 Solution
 
pagladasuCommented:
myString = buff; //converts char* to CString;

0
 
el_rookyAuthor Commented:
When I do that I get the following error:

error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'char *[2052]' (or there is no acceptable conversion)

I am using VC++6 and MFC
thanks
0
 
jcgdCommented:
myString.Format("%s",buf);
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
thienpnguyenCommented:


    char buf[50]
    CString myString;
    ...

    myString = buf;

 
or

    char *buf[50] // array of pointer
    CString myString;
    ...

    myString = *buf;

0
 
dchan_4544Commented:
First of all, are you trying to convert an array of chars or an array of "strings" ? (according to your example, you have char* buf[50], which is an array of strings (buf[50] is a string or array of characters)).  So, if you are just trying to convert an array of characters, then maybe you can do this:

char buf[50];
CString mystring;

strncpy(buf, "Bla Bla", sizeof(buf));
mystring = buf;

If you have an array of "strings" (array of array of characters), then maybe you can do this:

char* buf[50];
CString mystring;

buf[0] = new char[50];
strncpy(buf[0], "bla Bla", 50);
mystring = buf[0];
delete buf[0];

Hope that helps.
0
 
AxterCommented:
You should always initialize your variables when you declare them.

For example:
const char* buf = "Hello World";
CString myString = "Hey";

myString = myString + buf;

AfxMessageBox(myString);
0
 
pagladasuCommented:
Change the declaration of
char *buf[50];
to
char buf[50];
0
 
el_rookyAuthor Commented:
Thanks, I wasn't thinking yesterday.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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