If I use functions like absolute()
I always get a path which contains quotation marks.
Is there a way within the filesystem functions to remove this quotation marks which enables it to use with e.g. std::ifstream?
fs::path p2 { "./test/hallo.txt" };
std::cout << "absolte to file : " << fs::absolute(p2) << std::endl;
returns:
"/home/bla/blub/./test/hallo.txt"
I need
/home/bla/blub/./test/hallo.txt
instead.
It is no problem to do it manually, but I want to ask if there is a method inside the filesystem lib.
std::quoted is a function that belongs to the iomanip header. It is used to read and write quoted strings. CSV files and XML files often contain strings encapsulated in quotes.
std::operator << (std::filesystem::path const &)
is specified as follows:
Performs stream input or output on the path p.
std::quoted
is used so that spaces do not cause truncation when later read by stream input operator.
So this is expected behaviour when streaming a path. What you need is path::string()
:
Returns the internal pathname in native pathname format, converted to specific string type.
std::cout << "absolte to file : " << absolute(p2).string() << std::endl;
// ^^^^^^^^^
I've also removed fs::
since absolute
can be found via ADL.
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