Sign in to follow this  
de_matt

CString in non-MFC app?

Recommended Posts

Hya I've based my app on one of the tutorials in the SDK and now I want to use the CString class. However, when I include the class ( #include <cstring> ) and create a CString variable the compiler says it doesn't recognise the variable type. How do I sort this out? Should I use string instead? If I should could anyone tell me how to read each character from a string variable. I know how to do it with a CString. Thanks Matt

Share this post


Link to post
Share on other sites
when you include cstring, you are actually including string.h, which is not what you want.

However, if you are creating a non-MFC app, you should probably use the STL string class, which is in the string (not string.h) header file. Then, instead of "CString mystring", you would use "std::string mystring".

The STL string class has members similar to those in CString.

Share this post


Link to post
Share on other sites
Quote:
Original post by de_matt
...could anyone tell me how to read each character from a string variable.
std::string presents an array-like interface (operator[]) for unchecked element access and the at() method for range-bounded access.

MFC's CSring requires certain additional header files to introduce fundamental types, though it should include those itself. It most likely also requires certain environment variables that are not set by default. It's not a particularly good string class, anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this