c++ - 如何将 CString 转换为 long? VC++

标签 c++ visual-c++ mfc

如何在 VC++ 中将 CString 转换为 long。我用过 atol 但它抛出错误。

long ldata = atol(str);

没有从 CStringconst char* 的合适转换。

最佳答案

如前所述,您使用的是 Unicode。您必须使用 Unicode 来实现其他功能:

long ldata = _wtol(str);

里面某处CString声明是这样的:

#ifdef UNICODE
#define CString CStringW
#else 
#define CString CStringA
#endif

当项目编译为 Unicode 时,CString变成宽字符 CStringW , 所以你必须使用 atol 的宽字符版本这是_wtol对于所有其他字符串函数也是如此。

关于c++ - 如何将 CString 转换为 long? VC++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30747363/

相关文章:

c++ - 为什么我需要在 C++ 中使用 `size_t`?

c++ - 将类添加到 mfc 项目

c++ - 类成员不知何故不情愿地改变

c++ - 如何在链表中动态创建新节点C++

c++ - 使用 MapWindowPoints 时堆栈损坏

c - 这个表达式是什么意思,为什么编译?

c++ - mfc sdi 应用程序 cdocument dosave 错误 0xFEEEFEEE

c++ - 我能保证所有指针都具有相同的字节大小吗?

c++ - 有没有办法将类嵌入到同名的新命名空间中?

c++ - 将数组传递给函数并返回指针