Click here to Skip to main content
15,926,290 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralDirect3D and MDI windows Pin
29-Jun-02 11:28
suss29-Jun-02 11:28 
GeneralRe: Direct3D and MDI windows Pin
Mike Nordell29-Jun-02 23:47
Mike Nordell29-Jun-02 23:47 
Questionhow to add toolbar on a Dialog Pin
Speedy29-Jun-02 10:47
Speedy29-Jun-02 10:47 
AnswerRe: how to add toolbar on a Dialog Pin
Steve L.29-Jun-02 13:08
Steve L.29-Jun-02 13:08 
GeneralCString Basics Pin
29-Jun-02 10:36
suss29-Jun-02 10:36 
GeneralRe: CString Basics Pin
Nish Nishant29-Jun-02 11:24
sitebuilderNish Nishant29-Jun-02 11:24 
GeneralRe: CString Basics Pin
29-Jun-02 12:05
suss29-Jun-02 12:05 
GeneralRe: CString Basics Pin
Ancient Dragon29-Jun-02 12:46
Ancient Dragon29-Jun-02 12:46 
First, I think you, like may others, are confused about how computers actually store characters. In the English language (non-Englich languages may be store differently), each character (both printable and non-printable) is represented by a numeric value between 0 and 255. (Actually, at the machine level, they are represented by their binary values, but I won't go there.) You cannot put an "A" into either a CString or a char buffer. Instead, the "A" is always convertd to its numeric value. Charts are easily available that show what these numeric values are.

The Basic languages that I've used (although very seldon) have a function to convert "A" to its numeric equivalent. This is not necessary in C/C++, because they are already represented that way. So, if you have a CString that contains "Hello", then what that CString really contains is six bytes of numeric values (the 6th byte contains the null terminator 0 ).

How do you convert a "byte" to an "int" ? Simple:

char c = 'A';
unsigned char = 'A';
int x = 'A';
int x1 = 64; // numeric value of 'A'
int x2 = c; // converts a char to an int.

CString s = "Hello";
char c1 = s[1]; // extract the letter 'e' from CString
char buffer[126];
strcpy(buffer,s.GetBuffer(0)); // copy the contents of CString into a char buffer

I don't know why you would want to put a string array into an int array -- they can easily be represented in a char array (see above). But, if you did do that, you can put them into a CString like this:

int array[] = {'H','e','l','l','o',0 };
CString string;
for (int i = 0; array[i] != 0; i++)
string += (char)array[i]; // notice you need to type cast from int to char







GeneralRe: CString Basics Pin
29-Jun-02 13:25
suss29-Jun-02 13:25 
GeneralRe: CString Basics Pin
Christian Graus29-Jun-02 13:30
protectorChristian Graus29-Jun-02 13:30 
GeneralRe: CString Basics Pin
29-Jun-02 13:39
suss29-Jun-02 13:39 
GeneralRe: CString Basics Pin
Christian Graus29-Jun-02 13:41
protectorChristian Graus29-Jun-02 13:41 
GeneralRe: CString Basics Pin
Ancient Dragon29-Jun-02 14:10
Ancient Dragon29-Jun-02 14:10 
GeneralRe: CString Basics Pin
Christian Graus29-Jun-02 14:35
protectorChristian Graus29-Jun-02 14:35 
GeneralRe: CString Basics Pin
Ancient Dragon29-Jun-02 14:08
Ancient Dragon29-Jun-02 14:08 
GeneralRe: CString Basics Pin
29-Jun-02 15:07
suss29-Jun-02 15:07 
GeneralRe: CString Basics Pin
Ancient Dragon29-Jun-02 15:12
Ancient Dragon29-Jun-02 15:12 
GeneralRe: CString Basics Pin
Jay Beckert29-Jun-02 15:20
Jay Beckert29-Jun-02 15:20 
GeneralRe: CString Basics Pin
Michael Dunn29-Jun-02 15:15
sitebuilderMichael Dunn29-Jun-02 15:15 
GeneralRe: CString Basics Pin
aldeba29-Jun-02 15:31
aldeba29-Jun-02 15:31 
GeneralSendMessage() to a common file Open/Save dialog, telling it to change path Pin
Jonatan Dahl29-Jun-02 10:35
Jonatan Dahl29-Jun-02 10:35 
GeneralRelase mode can't compile after use getaddrinfo in VS.net Pin
Hiusing29-Jun-02 5:38
Hiusing29-Jun-02 5:38 
GeneralRe: Relase mode can't compile after use getaddrinfo in VS.net Pin
Mike Nordell29-Jun-02 23:55
Mike Nordell29-Jun-02 23:55 
QuestionSet "active window" on mouseover in dlg app? Pin
Nitron29-Jun-02 5:29
Nitron29-Jun-02 5:29 
AnswerRe: Set "active window" on mouseover in dlg app? Pin
Ravi Bhavnani29-Jun-02 6:31
professionalRavi Bhavnani29-Jun-02 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.