我应该在 ATL/WTL 中使用 CString、basic_string或其他内容吗?
最近几天我只学了一点ATL(在意识到纯Win32有多么痛苦之后),还了解了WTL和MFC,从我所见,有相当多不同的字符串类可供使用我。
我曾经做了这样的事情:
#include <tchar.h>
#include <string>
namespace std { typedef basic_string<TCHAR> _tstring; }
然后在我的代码中的任何地方使用_tstring
。在学习了一些ATL之后,我了解到atltmp.h
中有一个CString
类。显然,WTL 中还有一个 CString
类,MFC 中还有一个CString
类。
我不知道是否会坚持使用 ATL,或者是否会切换到 WTL、MFC 或其他东西。但现在,我正在将 Win32 代码转换为 ATL,我不确定要更改什么以及要保留什么。
我应该让我的字符串使用 CString
而不是 _tstring
吗?考虑到两者可执行文件大小(不包括共享库)和可移植性/兼容性,这样做有什么好处吗?
I've only learned a little bit of ATL in the last couple of days (after realizing how much pain pure Win32 is) and also learned about WTL and MFC, and from what I see, there are quite a few different string classes available for me.
I used to do something like this:
#include <tchar.h>
#include <string>
namespace std { typedef basic_string<TCHAR> _tstring; }
and then use _tstring
everywhere in my code. After learning some ATL, I learned that there's a CString
class in atltmp.h
. Apparently, there's another CString
class in WTL, and yet another CString
class in MFC.
I have no idea whether I will stick with ATL or whether I'll switch to WTL, MFC, or something else. But right now, I'm in the process of converting my Win32 code to ATL, and I'm not sure what to change and what to keep.
Should I make my strings use CString
instead of _tstring
? Is there any benefit in doing so, considering both executable size (excluding shared libraries) and portability/compatibility?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 ATL / MFC / WTL,我的偏好是坚持使用 CString。如果您无论如何都使用这些框架,那么您就没有太多可移植性的选择;你知道他们说什么:
When in Rome ...
另外,
CString
确实有一些优点CString 从可执行文件加载资源字符串: :LoadString
CString::GetBuffer/ReleaseBuffer
直接访问内部字符串缓冲区CStringA
和CStringA
之间进行静默转换。CStringW
CString::Format
执行类似printf
的格式化My preference would be to stick with
CString
for ATL / MFC / WTL. It's not like you have much of an option for portability if you're using those frameworks anyway; and you know what they say:When in Rome ...
Also,
CString
does have a few niceties about itCString::LoadString
CString::GetBuffer/ReleaseBuffer
CStringA
&CStringW
printf
-like formatting usingCString::Format
我刚刚读到的内容是
CString
不支持空字符。我想我会继续使用STL。
Something that I just read is that
CString
does not support null characters.I guess I'll keep with STL, then.