C++ mac&windows 獲取程序運行根目錄

 mac 

#include "iostream"
#include <unistd.h>
using namespace std;
int main(int argc, char** argv)
{
    const int MAXPATH=250;
    char buffer[MAXPATH];
    getcwd(buffer, MAXPATH);
    printf("The current directory is: %s", buffer);
}

windows

#include <stdio.h>  
#include <direct.h>  
int main()  
{  
    const int MAXPATH = 250;
    char buffer[MAXPATH];
    getcwd(buffer, MAXPATH);
    printf("The current directory is: %s", buffer);
}




發佈了105 篇原創文章 · 獲贊 13 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章