How to convert a char array to CString?
-
Hi All, How to convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,656); //reading some characters from the file CString str; how to store the charr array in to str? Regards, Kumar
-
Hi All, How to convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,656); //reading some characters from the file CString str; how to store the charr array in to str? Regards, Kumar
The easy answer is: you don't have to convert, just assign it. But it depends on your UNICODE setting. I suggest you read this article[^] to get a better understanding on character encodings. This will help you a lot in the future.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
The easy answer is: you don't have to convert, just assign it. But it depends on your UNICODE setting. I suggest you read this article[^] to get a better understanding on character encodings. This will help you a lot in the future.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Thanks Cedric! The given article is very help full Can't we convert the char array like this? Cstring str(charr); //charr is char array Regards, Kumar
-
Thanks Cedric! The given article is very help full Can't we convert the char array like this? Cstring str(charr); //charr is char array Regards, Kumar
Yes, the
CString
constructor is overloaded to accept that. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Thanks Cedric! The given article is very help full Can't we convert the char array like this? Cstring str(charr); //charr is char array Regards, Kumar
As I said in my previous reply, it all depends on your UNICODE setting. BTW, why don't you just check ? It's one line of code and you can easily verify if it compiles or not. If UNICODE is turned on, the code won't compile.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
As I said in my previous reply, it all depends on your UNICODE setting. BTW, why don't you just check ? It's one line of code and you can easily verify if it compiles or not. If UNICODE is turned on, the code won't compile.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Nope. It will work.
CString
constructor automatically handles the conversion, see [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Thanks Cedric! The given article is very help full Can't we convert the char array like this? Cstring str(charr); //charr is char array Regards, Kumar
Just be carefull, your char array has to be null-terminated to be used to initialize a CString like that or even if you use the = operator (
CString str; str = charr;
). Othwerwise it will keep on reading characters till it finds a null character somewhere after your array and which either results in access violation OR you get garbage in your str.> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <