The following program compiles in Visual Studio 2008 under Windows, both with Character Set "Use Unicode Character Set" and "Use Multi-Byte Character Set". However, it does not compile under Ubuntu 10.04.2 LTS 64-bit and GCC 4.4.3. I use Boost 1.46.1 under both environments.
#include <boost/filesystem/path.hpp>
#include <iostream>
int main() {
boost::filesystem::path p(L"/test/test2");
std::wcout << p.native() << std::endl;
return 0;
}
The compile error under Linux is:
test.cpp:6: error: no match for ‘operator<<’ in ‘std::wcout << p.boost::filesystem3::path::native()’
It looks to me like boost::filesystem under Linux does not provide a wide character string in path::native(), despite boost::filesystem::path having been initialized with a wide string. Further, I'm guessing that this is because Linux defaults to UTF-8 and Windows to UTF-16.
So my first question is, how do I write a program that uses boost::filesystem and supports Unicode paths on both platforms?
Second question: When I run this program under Windows, it outputs:
/test/test2
My understanding is that the native() method should convert the path to the native format under Windows, which is using backslashes instead of forward slashes. Why is the string coming out in POSIX format?