在Non-Mfc下使用CString
2012-01-13 10:32
260 查看
Users of Visual Studio 2003 and newer may directly go to below and skip this one.
/article/8848423.html
//z 2012-1-13 10:36 is2120@csdn
方法一
- - -
Q: How to use 'CString' in non-MFCapplications?
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 theentireMFC. This would not only increase the size of your executable file, the numberof its dependencies,
but also makes your program non-portable (especially if itis a Console application).
The recommended solution is to use the Standard C++ Class 'std::string'. It isas powerful as 'CString', is portable, using it does not imply adding a hugeamount of things you don't need to your project and last, but not least, it ispartof the programming
language.
This being said, if you still want to use 'CString' in your non-MFCapplication, here it is whar you have to do:
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.
A simple sample of a console application using 'CString'looks like this:
Code:
#include<afx.h>
#include<iostream>
intmain()
{
CString s("Hello");
std::cout << s.GetBuffer(0) << std::endl;
return 0;
}
//z 2012-1-13 10:36 is2120@csdn
方法二:从vs2003开始,你可以使用 <atlstr.h>
Starting VS 2003, you can useCString in non-MFC applications by including header atlstr.h:
Code:
#include <atlstr.h>
A sample console application withCString:
Code:
#include <atlstr.h>
#include <iostream>
int main ()
{
CString strTest (_T("This is aCString in a console application!"));
#ifdef UNICODE
std::wcout << (LPCTSTR)strTest;
#else
std::cout << (LPCTSTR)strTest;
#endif
return 0;
}
You canalso use CStringA as a ANSI string class, and CStringW as a wide-characterstring class.
方法三:可以使用 boost 中的 string
BoostString Algorithms Library
//z 2012-1-13 10:36 is2120@csdn
/article/8848423.html
//z 2012-1-13 10:36 is2120@csdn
方法一
- - -
Q: How to use 'CString' in non-MFCapplications?
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 theentireMFC. This would not only increase the size of your executable file, the numberof its dependencies,
but also makes your program non-portable (especially if itis a Console application).
The recommended solution is to use the Standard C++ Class 'std::string'. It isas powerful as 'CString', is portable, using it does not imply adding a hugeamount of things you don't need to your project and last, but not least, it ispartof the programming
language.
This being said, if you still want to use 'CString' in your non-MFCapplication, here it is whar you have to do:
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.
A simple sample of a console application using 'CString'looks like this:
Code:
#include<afx.h>
#include<iostream>
intmain()
{
CString s("Hello");
std::cout << s.GetBuffer(0) << std::endl;
return 0;
}
//z 2012-1-13 10:36 is2120@csdn
方法二:从vs2003开始,你可以使用 <atlstr.h>
Starting VS 2003, you can useCString in non-MFC applications by including header atlstr.h:
Code:
#include <atlstr.h>
A sample console application withCString:
Code:
#include <atlstr.h>
#include <iostream>
int main ()
{
CString strTest (_T("This is aCString in a console application!"));
#ifdef UNICODE
std::wcout << (LPCTSTR)strTest;
#else
std::cout << (LPCTSTR)strTest;
#endif
return 0;
}
You canalso use CStringA as a ANSI string class, and CStringW as a wide-characterstring class.
方法三:可以使用 boost 中的 string
BoostString Algorithms Library
//z 2012-1-13 10:36 is2120@csdn
相关文章推荐
- VC程序在非MFC中使用CString
- MFC CString的使用
- VC程序在非MFC中使用CString
- MFC中CString的使用总结
- MFC中使用TRACE宏输出CString对象中的字符串
- 在非MFC中使用CString
- MFC中使用CString时遇见的问题
- 非MFC项目使用CString及如何打印
- 在非MFC项目中使用CString
- MFC中CString的Format方法使用技巧
- MFC AtlMap<CString, ?>使用
- MFC CString GetBuffer/ReleaseBuffer 的使用条件
- 在非MFC环境中使用CString、使用_bstr_t
- VC程序在非MFC中使用CString
- MFC 常用类 Cstring 方法使用:
- MFC CString 查找函数使用的三个失误
- 非MFC中使用Cstring
- VC下Non-MFC DLL创建和使用
- MFC中CString的Format方法使用技巧
- MFC中CString的Format方法使用