Computing.Net > Forums > Programming > v.c++changing cstring to char array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

v.c++changing cstring to char array

Reply to Message Icon

Name: twend34
Date: May 4, 2006 at 10:32:33 Pacific
OS: window
CPU/Ram: pentium4
Product: microsoft
Comment:

I want a small code which can change CString to a char array.Or I want how can I assign the string I get from a user through my edit box in a dialog box to a char array to access each letter .please respond



Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: May 6, 2006 at 05:26:25 Pacific
Reply:

CString str;
char a, b, c;
char *cstr = new char[20];
char *dstr = new char[20];

str = "Hello World!"; // set initial string data
a = str[4]; // get single character at index 4
b = str.GetAt(6); // get single character at index 6
c = 'Z';
str.SetAt(5,c); // set single character at index 5
strcpy(cstr, LPCTSTR (str)); // copy char character array
str = "dog & cat";
strcpy(dstr, str); // copy char character array

final result:
a = 'o'
b = 'W'
c = 'Z'
str = "dog & cat"
cstr = "HelloZWorld!"
dstr = "dog & cat"


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: v.c++changing cstring to char array

Change value in char array in C www.computing.net/answers/programming/change-value-in-char-array-in-c/10213.html

Converting a String to a char array www.computing.net/answers/programming/converting-a-string-to-a-char-array/3190.html

C++ 2 dimensional char array www.computing.net/answers/programming/c-2-dimensional-char-array/10085.html