C++ Poco::Path使用常量wchar\u t*编译,但行为异常

C++ Poco::Path使用常量wchar\u t*编译,但行为异常,c++,poco-libraries,wstring,C++,Poco Libraries,Wstring,我发现了一个非常奇怪的错误。请参阅以下代码: #include <iostream> #include <string> #include <Poco/Path.h> int main() { std::wstring a_path = L"c:\\temp"; //Poco::Path from_wstring(a_path); // ERROR: fails to compile, expected Poco::Path from_wcha

我发现了一个非常奇怪的错误。请参阅以下代码:

#include <iostream>
#include <string>
#include <Poco/Path.h>

int main()
{
  std::wstring a_path = L"c:\\temp";

  //Poco::Path from_wstring(a_path); // ERROR: fails to compile, expected
  Poco::Path from_wchar_t(a_path.c_str()); // compiles... unexpected

  std::cout << from_wchar_t.toString() << std::endl;

  return 0;
}
#包括
#包括
#包括
int main()
{
std::wstring a_path=L“c:\\temp”;
//Poco::Path from_wstring(a_Path);//错误:编译失败,应为
Poco::来自_wchar_t的路径(a_Path.c_str());//编译…意外
std::cout在为这个问题创建文档时,我发现了问题所在。我决定将它记录在这里,以防对其他人有所帮助

问题中显示的代码片段是一个大型项目的一部分,因此我遗漏了一条编译警告:

警告C4800:'const wchar_t*':强制将值设置为布尔值'true'或'false'(性能警告)

然后我意识到有一个构造函数
Poco::Path::Path(bool absolute)
,编译器正在自动将指针转换为bool,然后产生意外的行为。输出的
\
对应于一个空的绝对路径,即使用这种构造函数时的初始值


对于那些对解决方案感兴趣的人,我现在使用UTF-16到UTF-8转换:

#include <boost/locale/encoding.hpp>
// ...
std::wstring a_path = L"c:\\temp";
Poco::Path utf8_path(boost::locale::conv::utf_to_utf<char>(a_path));
#包括
// ...
std::wstring a_path=L“c:\\temp”;
Poco::Path utf8_路径(boost::locale::conv::utf_to_utf(a_路径));

供将来参考:所有POCO接口(显然,转换接口除外)都需要UTF-8字符串。如果需要,任何转换都由内部处理。