#create filesystem path

1 messages · Page 1 of 1 (latest)

buoyant siren
#

How can I create a filesystem path with the string? I've been searching this up and i can't seem to solve the problem.

south owl
#

In C++, creating a filesystem path is easiest with the standard library’s C++17 std::filesystem (available since C++17).

Example:

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main() {
// Create a path object
fs::path myPath = "folder/subfolder/file.txt";

std::cout << "Path: " << myPath << std::endl;

// Create directories if they don't exist
fs::create_directories("folder/subfolder");

return 0;

}

#

If you're using an older compiler (pre-C++17), you’d need Boost.Filesystem instead.

buoyant siren
buoyant siren
#

oh wait no, im pretty sure im using clang

round thistle
#

Try doing

#

fs::path var = std::string("ur steing")

#

Maybe ts work

round thistle
buoyant siren
round thistle
buoyant siren
#

to see if it'll error

round thistle
#

Try

buoyant siren
#

im assuming it wouldve failed on compiling with a syntax error or type error

round thistle
#

Now u gotta fic the visual studio erorr

buoyant siren
#

not sure why it's doing that

#

just tried to restart the language server, but it still shows

buoyant siren
#

gonna use this thread instead of making a new one. I've made this bit where it replaces the files and it works on linux when it's overwritten while it's running.

#

However, Windows is different. It would not allow that, for some reason. Is there a workaround for it?