⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p4.2.cxx

📁 linux编程源代码,其中是由大量的实例
💻 CXX
字号:
/*program p4.2.cxx: using pathconf and getcwd together */

#include <unistd.h>
#include <iostream>

int main(void){
   long cur_path_len;
   char* cur_work_dir;
   
   /*获得目录最大长度*/
   if((cur_path_len=pathconf(".",_PC_PATH_MAX))==-1){
      perror("Couldn't get current working path length");
      return 1;
   }

  std::cout<<"Current Path Length Is "<<cur_path_len<<std::endl;
  
  /*根据获得的目录最大长度,分配内存*/
  if((cur_work_dir=(char *)malloc(cur_path_len))==NULL){
      perror("Couldn't allocate memory for the pathname");
      return 1;
  }
  
  /*得到当前工作目录*/
  if(getcwd(cur_work_dir,cur_path_len)==NULL){
      perror("Couldn't get current working directory");
      return 1;
  }

  std::cout<<"Current Working Directory IS"<<cur_work_dir<<std::endl;
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -