Here is my code:
fs::path datadir = ...;
std::string dataDirOption((boost::format("--datadir=%1%") % datadir).str());
For datadir=="c:/db"
I get dataDirOption=="--datadir=\"c:/db\""
, instead of "--datadir=c:/db"
Is it possible to tell boost::filesystem::path
to skip the quotes when being formatted?
Now, I know I can substitute datadir.string()
for datadir
and get rid of the quotes in this way, but I am wondering whether I can do so without the extra string.
Thanks.
No it is not, is is a bug files on the boost framework version 1.47.0 which has not yet been given a milestone on when to be fixed.
The workaround however is:
std::cout << path("/foo/bar.txt").filename().string()
The %
operator for format
uses the <<
stream-insertion operator for user-defined types, and the documentation tells us it's effectively the following for path
:
os << boost::io::quoted(p.string<std::basic_string<Char>>(), static_cast<Char>('&'));
To leave out the quotes, you need to pass something different to the format
object, such as the output of the string
method as you've already discovered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With