#include <cstddef>
#include <iostream>
#include <unistd.h>
using namespace std;
int main(){
char* c = NULL;
c = getcwd(NULL, 0);
if(c){
std::string path = c;
free(c);
cout << path; // /opt/project/test
}
cout << "no path" << endl;
}
getcwd()函数:获取当前程序运行目录
于 2023-04-15 14:18:20 首次发布