Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove quotation marks from std::filesystem::path

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.

like image 324
Klaus Avatar asked Apr 27 '17 13:04

Klaus


People also ask

What is std:: quoted?

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.


1 Answers

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.

like image 99
Quentin Avatar answered Oct 09 '22 01:10

Quentin