CString in non-MFC app?

Started by
3 comments, last by de_matt 19 years, 7 months ago
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
Advertisement
Let's ask Google

I personally think that switching to std::string is the best solution.
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.
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.
Thanks everyone. I'll go and have a play with <string>

Matt

This topic is closed to new replies.

Advertisement