C++ C++;:Boost:需要目录导航逻辑的帮助吗

C++ C++;:Boost:需要目录导航逻辑的帮助吗,c++,boost,boost-filesystem,C++,Boost,Boost Filesystem,因此,我试图更改我的目录以保存文件,然后更改回以前所在的目录 基本上: cd folder_name <save file> cd ../ cd文件夹\u名称 cd/ 以下是我目前掌握的代码: void save_to_folder(struct fann * network, const char * save_name) { boost::filesystem::path config_folder(Config::CONFIG_FOLDER_NAME); b

因此,我试图更改我的目录以保存文件,然后更改回以前所在的目录

基本上:

cd folder_name
<save file>
cd ../
cd文件夹\u名称
cd/
以下是我目前掌握的代码:

void save_to_folder(struct fann * network, const char * save_name)
{
    boost::filesystem::path config_folder(Config::CONFIG_FOLDER_NAME);
    boost::filesystem::path parent_folder("../");


    if( !(boost::filesystem::equivalent(config_folder, boost::filesystem::current_path())))
        {
            if( !(boost::filesystem::exists(config_folder)))
            {
                std::cout << "Network Config Directory not found...\n";
                std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
                boost::filesystem::create_directory(config_folder);
            }
            boost::filesystem::current_path(config_folder);
        }

    fann_save(network, save_name);
    boost::filesystem::current_path(parent_folder);

}
void save_to_folder(struct fann*network,const char*save_name)
{
boost::filesystem::path config_folder(config::config_folder_NAME);
boost::filesystem::path父文件夹(“../”;
if(!(boost::filesystem::equivalent(config_文件夹,boost::filesystem::current_path()))
{
如果(!(boost::filesystem::exists(配置文件夹)))
{

std::cout你能用这个代码代替吗

void save_to_folder(struct fann * network, const char * save_name)
{
    boost::filesystem::path configPath(boost::filesystem::current_path() / Config::CONFIG_FOLDER_NAME);

   if( !(boost::filesystem::exists(configPath)))
   {
       std::cout << "Network Config Directory not found...\n";
       std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
       boost::filesystem::create_directory(configPath);
   }
   fann_save(network, save_name);
}
void save_to_folder(struct fann*network,const char*save_name)
{
boost::filesystem::path configPath(boost::filesystem::current\u path()/Config::Config\u FOLDER\u NAME);
如果(!(boost::filesystem::exists(configPath)))
{

std::cout你能用这个代码代替吗

void save_to_folder(struct fann * network, const char * save_name)
{
    boost::filesystem::path configPath(boost::filesystem::current_path() / Config::CONFIG_FOLDER_NAME);

   if( !(boost::filesystem::exists(configPath)))
   {
       std::cout << "Network Config Directory not found...\n";
       std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
       boost::filesystem::create_directory(configPath);
   }
   fann_save(network, save_name);
}
void save_to_folder(struct fann*network,const char*save_name)
{
boost::filesystem::path configPath(boost::filesystem::current\u path()/Config::Config\u FOLDER\u NAME);
如果(!(boost::filesystem::exists(configPath)))
{

std::cout根据文档,当前的_路径方法有点危险,因为它可能同时被其他程序修改

因此,从CONFIG_文件夹_名称进行操作可能会更好

能否将更大的路径名传递给fann_save?类似于:

if( !(boost::filesystem::exists(config_folder)))
{
    std::cout << "Network Config Directory not found...\n";
    std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
    boost::filesystem::create_directory(config_folder);
}
fann_save(network, (boost::format("%s/%s") % config_folder % save_name).str().c_str());
boost::filesystem::path up_folder((boost::format("%s/..") % Config::CONFIG_FOLDER_NAME).str());
boost::filesystem::current_path(up_folder);

根据文档,当前的_path方法有点危险,因为它可能同时被其他程序修改

因此,从CONFIG_文件夹_名称进行操作可能会更好

能否将更大的路径名传递给fann_save?类似于:

if( !(boost::filesystem::exists(config_folder)))
{
    std::cout << "Network Config Directory not found...\n";
    std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
    boost::filesystem::create_directory(config_folder);
}
fann_save(network, (boost::format("%s/%s") % config_folder % save_name).str().c_str());
boost::filesystem::path up_folder((boost::format("%s/..") % Config::CONFIG_FOLDER_NAME).str());
boost::filesystem::current_path(up_folder);

我认为您可以删除最后一行代码
boost::filesystem::current_path(parent_folder);
。每当您输入函数时,您都会将路径设置为要处理的文件夹。我不会将“./”用于父文件夹,而只是“..”。我认为您可以删除最后一行代码
boost::filesystem::current_path(parent_folder);
。每当您输入函数时,都会设置要处理的文件夹的路径。我不会将“./”用于父文件夹,而只使用“..”。