About conversion of os.path.join in C++

Hi, All

I have inquiry about how to realize os.path.join in C++ In libtorch

In python, it is
Torch::load(os.path.join(arg.savedir,‘d.pkl’)

Many thanks.

os is a Python lib and thus not available in C++.
You could use e.g. std::filesystem to use a similar as pathlib:

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main() 
{
    fs::path dir ("/tmp");
    fs::path file ("foo.txt");
    fs::path full_path = dir / file;
    std::cout << full_path << std::endl;
    return 0;
}

Code taken from here.

Thank you very much. I appreciate that.

One more inquiry is that if pytorch
Is model=torch.load(fullpath)

In c++, shall I use torch::load(model,full path) as I cannot use model=torch::load(full path)

Also how shall I convert

Os.makedir(path) to c++

Thanks a lot.

auto module = torch::jit::load(path); might work.

mkdir is also a C++ function as described here.

Thanks a lot. That is very helpful.

But actually it says "no matching function for ‘mkdir’.

What shall I include in the header file in order to find mkdir function please ?

Thanks

The link gives you full examples for Windows and Linux systems.
On Linux mkdir should be defined in <sys/stat.h>.

Thanks.

It seems that even if I include <sys/stat.h>, it stills says no matching function call to “mkdir”. I am in linux, in libtorch

This is the right header though. See an example here:
https://coliru.stacked-crooked.com/a/ace3992a9a0d474e
The related man page: