c++ - 如何将 OutputDebugString 与 std::string 一起使用?
问题描述
我正在尝试做:
std::string line = "bla";
OutputDebugString( line.c_str() );
它不会编译,说它不能转换const char*
为LPCWSTR
. 有没有办法输出std::string
到调试窗口?
我也不明白为什么这似乎在本教程视频中起作用:https ://youtu.be/EIzkeFTpMq0?list=PLqCJpWy5Fohfil0gvjzgdV4h29R9kDKtZ&t=2101
解决方案
您的项目配置为针对 Unicode 进行编译,因此OutputDebugString()
映射到OutputDebugStringW()
,它需要 aconst wchar_t*
作为输入,而不是 a const char*
,因此会出现错误。
视频中的代码有效,因为演示者的项目配置为针对 ANSI 进行编译,因此改为OutputDebugString()
映射到OutputDebugStringA()
。
因此,您需要:
使用
std::wstring
而不是std::string
:std::wstring line = L"bla"; OutputDebugString( line.c_str() );
使用
OutputDebugStringA()
而不是OutputDebugString()
:std::string line = "bla"; OutputDebugStringA( line.c_str() );
推荐阅读
- python - 强制 Dlib python 仅在 CPU 支持下安装;在带有 Cuda 和一切的 GPU 机器上
- wpf - WPF Listview 可以在布局中嵌入不同高度的元素吗?
- php - 邮件未到达特定收件人
- javascript - Javascript对象循环搜索数据
- sass - SCSS 文件观察器无法打开文件 - WebStorm
- node.js - 如何设置参数以在nodejs中压缩文件夹
- python - 使用networkx对边缘进行约束的图同构
- reactjs - 如何以功能方式使用钩子更新我的反应组件
- laravel - Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR) 方法名必须是字符串
- c# - 分析 Entity Framework 6 中的缓慢延迟加载