dojo_user
dojo_user

Reputation: 85

boost::filesystem::path gives only first char

I store path to some executable in boost::filesystem::path. When I try to use it with standard boost functions like create_directory I see that nothing works. When I print the value stored in boost::filesystem::path I get only the first char.

const std::string path("c:\\test\\file");
boost::filesystem::path p(path);
printf("%s\n", p.c_str());

I expect to see "c:\test\file" in console but get only "c".

On Linux this code works perfectly as expected. On Windows I have behaviour as I described. What is the root of a problem?

ps. boost library version is 1.70

Upvotes: 0

Views: 580

Answers (2)

StPiere
StPiere

Reputation: 4243

for getting std::string instead of std::wstring crossplatform, u can use boost::fileystem::path::string() instead of c_str():

const std::string path("c:\\test\\file");
boost::filesystem::path p(path);
std::cout << p.string();

Upvotes: 3

gluttony
gluttony

Reputation: 569

In addition to @StPiere's answer (I cannot comment it because of not enough reputation), this is not mandatory to use

std::cout

even with

boost::fileystem::path::string()

you can just change the code in your question to:

const std::string path("c:\\test\\file");
boost::filesystem::path p(path);
printf("%s\n", p.string().c_str());

Upvotes: 0

Related Questions