std::filesystem in c++17

twitter

I was thinking that maybe C++ had some support for paths by now … something like Python. And it does, std::filesystem! It is in C++17, and a little funky to get to compile and link. My indexer does absolutely nothing to help with function suggestions, so I am heavily using the docs. But it is super cool. A function call replace_extension, instead of walking through a string to find the ., I’m in love.

Also: extension – what is this path’s extension? Super handy.

Now for the compiling part. The links above have lots of MWE-type examples, and on the bottom of filesystem is a note about compiler support.

On Ubuntu 20.04, I use CMake and used gcc 9.3.0 and the -std=c++17 compiler flag. Then I ran into some linking problems, so I just added stuff until it linked. Adding libraries stdc++ and m seemed to do the trick.

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.