By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,301 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,301 IT Pros & Developers. It's quick & easy.

CString vs string? ComboBox help

P: 36
Could someone explain the difference between CString and string? I'm looking to use a getline kind of function to read off a file.

Also how would I initalize variables in a combobox?
Mar 22 '07 #1
Share this Question
Share on Google+
3 Replies

P: 99
well (and im assuming from your previous thread) that you are using MFC?

i dont think that there is too much of a difference between the two, except that microsoft recommends that you use cstrings with their products.

check out:
Mar 23 '07 #2

P: 99

im pretty sure that cstring is a microsoft creation which they are promoting as an all-purpose string-like data structure. im pretty sure also that there is no real functional difference between the two. (besides, of course, syntax)

the only real advantage, i would say, is that cstring will probably work better if you are using microsoft products. (god, i wish i knew why . . . ;))

(actually, from what i read on that site, i half-suspect that cstring is just a wrapper for the string class . . . but thats unconfirmed.)
Mar 23 '07 #3

Expert Mod 5K+
P: 8,916
One of the main "useful" features of CString is that it contains an operator to cast to LPCSTR (that is a far pointer to a constant char or an unchangeable string). This is useful because it means you can use a CString in all the WIN32 API functions that accept an LPCSTR (which is a lot of them) as well as standard library functions like strcpy which accept const char * (which is equivilent to LPCSTR in WIN32).

CString also contains a method that will fill the CString in much the same way that sprintf fills a char array.

The useful feature of a string is that it is a standard C++ type so by using string you code will be more portable to other platforms.
Mar 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.