C/C 获得当前程序路径

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

Windows下,

获得工作目录如下:

  1. #include  <direct.h>  
  2. #include  <stdio.h>  
  3.     char   buffer[MAX_PATH];   
  4.     getcwd(buffer, MAX_PATH);   
  5.     printf( "The   current   directory   is:   %s ",   buffer);   
  6. //打印出E:/C++/cppTest/cppPrimerTest  
#include  <direct.h>#include  <stdio.h> char   buffer[MAX_PATH];  getcwd(buffer, MAX_PATH);  printf( "The   current   directory   is:   %s ",   buffer); //打印出E:/C++/cppTest/cppPrimerTest 

 

获得exe当前目录:

  1. #include <windows.h>  
  2.     char chpath[MAX_PATH];  
  3.     GetModuleFileName(NULL,(LPSTR)chpath,sizeof(chpath));  
  4.     std::cout<<chpath<<std::endl;  
  5. //打印出:E:/C++/cppTest/cppPrimerTest/Debug/cppTest.exe  
#include <windows.h> char chpath[MAX_PATH]; GetModuleFileName(NULL,(LPSTR)chpath,sizeof(chpath)); std::cout<<chpath<<std::endl;//打印出:E:/C++/cppTest/cppPrimerTest/Debug/cppTest.exe 

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

版权声明:本文为yttyffggh原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。