谁有c++类型转换的类库

time_is_life 2015-05-03 07:45:55
在编程的时候经常遇到类型转换的问题。
比如tchar*转换成char*, int转换成char*等等。每次都要写好几行代码。
难道c++发展了这么久,就没有一个成熟的类库吗?简单调用一个函数就得到了要转换的类型。那样多好啊。

谁有这样的好类库啊?谢谢。
...全文
116 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoSaiMingMFC 2015-05-04
  • 打赏
  • 举报
回复
引用 楼主 time_is_life 的回复:
在编程的时候经常遇到类型转换的问题。 比如tchar*转换成char*, int转换成char*等等。每次都要写好几行代码。 难道c++发展了这么久,就没有一个成熟的类库吗?简单调用一个函数就得到了要转换的类型。那样多好啊。 谁有这样的好类库啊?谢谢。
一般情况下直接用已经写好的库,比如BOOST,如果觉得性能差的话就自已写。我们用的是XproerUI库里面提供的封装类。
activexme 2015-05-04
  • 打赏
  • 举报
回复
楼主说的是类似于图上的这种封装库吗?
time_is_life 2015-05-04
  • 打赏
  • 举报
回复
引用 1 楼 activexme 的回复:
楼主说的是类似于图上的这种封装库吗?
对,就是这样的,能否发给我一个。谢谢。
赵4老师 2015-05-04
  • 打赏
  • 举报
回复
String Conversion Macros The string conversion macros discussed here are valid for both ATL and MFC. For more information on MFC string conversion, see TN059: Using MFC MBCS/Unicode Conversion Macros and MFC Macros and Globals. The syntax of the string-conversion macros is: MACRONAME( string_address ) For example: A2W(lpa) In the macro names, the source string type is on the left (for example, A) and the destination string type is on the right (for example, W). A stands for LPSTR, OLE stands for LPOLESTR, T stands for LPTSTR, and W stands for LPWSTR. Thus, A2W converts an LPSTR to an LPWSTR, OLE2T converts an LPOLESTR to an LPTSTR, and so on. The destination string is created using _alloca, except when the destination type is BSTR. Using _alloca allocates memory off the stack, so that when your function returns, it is automatically cleaned up. If there is a C in the macro name, the macro converts to a const string. For example, W2CA converts an LPWSTR to an LPCSTR. Note When using an ATL string conversion macro, specify the USES_CONVERSION macro at the beginning of your function in order to avoid compiler errors. For example: void func( LPSTR lpsz ) { USES_CONVERSION; ... LPWSTR x = A2W(lpsz) // Do something with x ... } The behavior of the ATL string conversion macros depends on the compiler directive in effect, if any. If the source and destination types are the same, no conversion takes place. Compiler directives change T and OLE as follows: Compiler directive in effect T becomes OLE becomes none A W _UNICODE W W OLE2ANSI A A _UNICODE and OLE2ANSI W A The following table lists the ATL string conversion macros. ATL String Conversion Macros A2BSTR OLE2A T2A W2A A2COLE OLE2BSTR T2BSTR W2BSTR A2CT OLE2CA T2CA W2CA A2CW OLE2CT T2COLE W2COLE A2OLE OLE2CW T2CW W2CT A2T OLE2T T2OLE W2OLE A2W OLE2W T2W W2T ATL Macros and Global Functions See Also DEVMODE and TEXTMETRIC String Conversion Macros
oyljerry 2015-05-04
  • 打赏
  • 举报
回复
用最新的C++11,对字符串类做了一些改进
worldy 2015-05-04
  • 打赏
  • 举报
回复
自己封装一个就是了,如果是字符串,直接使用CString\CstringA\CstringW char* px="abcd"; CstringW csw(px); 可以直接转换,反之也行
Eleven 2015-05-04
  • 打赏
  • 举报
回复
自己封装一下,无非就是WideCharToMultiByte/MultiByteToWideChar()

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧