February 14th, 2003, 03:10 AM
C++ String: How to use 'CString' in non-MFC applications?
Users of Visual Studio 2003 and newer may directly go to the next post#2 and skip this one.
- - -
Q: How to use 'CString' in non-MFC applications?
A: In most cases, you don't need to do that. In order to use 'CString' you have to statically or dynamically link your application to the entire MFC. This would not only increase the size of your executable file, the number of its dependencies, but also makes your program non-portable (especially if it is a Console application).
The recommended solution is to use the Standard C++ Class 'std::string'. It is as powerful as 'CString', is portable, using it does not imply adding a huge amount of things you don't need to your project and last, but not least, it is part of the programming language.
This being said, if you still want to use 'CString' in your non-MFC application, here it is whar you have to do:
A simple sample of a console application using 'CString' looks like this:
- Include 'afx.h' in one of your main headers
- Open the menu 'Project -> Settings'. On the 'General' register of the settings dialog box choose 'Use MFC in a Shared DLL' or 'Use MFC in a Static Library' from the dropdown box called 'Microsoft Foundation Classes'.
- Rebuild your project.
std::cout << s.GetBuffer(0) << std::endl;
Last edited by JeffB; June 17th, 2009 at 02:35 PM.
Reason: Fixed include using html characters
Click Here to Expand Forum to Full Width