Question

When using boost_filesystem, Boost keeps adding quotation marks to the filenames.

foo.cpp:

#include <iostream>
#include <boost/filesystem.hpp>

int main( int argc, char * argv[] )
{
    std::cout << argv[0] << std::endl;
    boost::filesystem::path p( argv[0] );
    std::cout << p << std::endl;
    std::cout << p.filename() << std::endl;
    return 0;
}

Compiled:

g++ foo.cpp -o foo -lboost_filesystem -lboost_system

Output:

./foo
"./foo"
"foo"

This is somewhat unexpected, and inconvenient in my case. Is this really intentional, or is my somewhat older version of Boost (1.46.1) buggy in this respect? Is there some way I could avoid them being added?

I perused the documentation, but aside from the tutorials not showing those quotation marks in their example output, I was not enlightened.

Was it helpful?

Solution

This is actually a bug filed on the Boost framework on version 1.47.0.

The proposed workaround is:

std::cout << path("/foo/bar.txt").filename().string()

OTHER TIPS

It's intentional because unexpected embedded spaces and confuse related code. The best you can do is probably:

boost::replace_all(yourquotedstring, "\"", "");

EDIT

Although, according to this link, you can try something like:

std::cout << path("/foo/bar.txt").filename().string(); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top