1. 程式人生 > >mkdir建立目錄問題

mkdir建立目錄問題

教訓:不能建立多級目錄。。。改為逐級建立,或者手動建立上一級目錄。

測試cpp:

#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
int main(int argc, char **argv)
{   
    int status;
    std::string foldername = "/home/lyk/test/mm/5.0";//絕對目錄
    // std::string foldername = "../flor";//當前目錄
    // std::string foldername = "./flor";//相對目錄
    // status = mkdir("/home/test/flor", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 
    // status = mkdir(foldername.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    status = mkdir(foldername.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    std::cout<<status<<std::endl; 
}

測試cmake:

cmake_minimum_required(VERSION 2.8.3)
add_executable(hello_world_node hello_world_node.cpp)
target_link_libraries(hello_world_node ${catkin_LIBRARIES})