CMake builds for modern C++
Non-standard language options and incomplete feature support are normal for compilers across virtually all programming languages from BASIC to Fortran and here C++. Modern C++ features typically require using specific compiler flags to enable support. Knowing what compiler flags to set can be confusing for those new to modern C++ features. Setup of C++ compiler flags for modern C++ features is easily and automatically handled by CMake.
add_executable(filesep_cpp filesep.cpp)
target_compile_features(filesep_cpp PRIVATE cxx_std_17)
C++ fstream
allows writing files to disk.
Some operations need to manage directory slashes (Windows vs. POSIX).
C++
std::filesystem::path::preferred_separator
manages platform-agnostic path separators.
Akin to Python pathlib
, use std::filesystem::path
.
C++ filesystem works on almost all current C++ compilers.
#include <filesystem>
#include <iostream>
int main() {
std::cout << std::filesystem::path::preferred_separator << "\n";
return 0;
}