c++ 获得程序所在目录

    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 
      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 
posted @ 2016-03-02 18:15  简单数字  阅读(2627)  评论(0编辑  收藏  举报