我运行以下命令,它总是返回null,因为Bitmap文件由于某种原因无法打开。请帮忙!
const XCHAR* szFilePathW = L"C:\\Users\\Simrat\\Desktop";
std::ofstream bmpF;
char szFilePathA[MSO_MAX_PATH]; // std::ofstream.open() takes char* in Android C++ compiler, whereas it takes both char* and wchar* in VC++
WideCharToMultiByte(CP_UTF8, 0, szFilePathW, -1, szFilePathA, MSO_MAX_PATH, NULL, NULL);
bmpF.open(szFilePathA, std::ofstream::binary | std::ofstream::out);
if (!bmpF.is_open())
return null;
可以在此处找到WideCharToMultiByte()函数的功能: https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx
答案 0 :(得分:0)
如评论所示,您似乎缺少文件名。代码应该只是:
const WCHAR* szFilePath = L"C:\\Users\\Simrat\\Desktop\\name_of_bitmap_file_I_want_to_create.bmp";
std::ofstream bmpF;
bmpF.open (szFilePath, std::ofstream::binary | std::ofstream::out);
无需转换为多字节,请参阅MSDN(请注意open
文件名参数的const wchar_t *
重载 - 在Windows上。)