C++,获取当前工作路径

2023年6月21日13:09:40

需要包含的头文件:

#include <direct.h>
#include <iostream>

函数如下:

std::string GetCWD()
{
	const int MAX_LENGTH = 512;
    char buffer[MAX_LENGTH];

    getcwd(buffer, 512);
    std::string cwd = buffer;

    int pos = cwd.find("\\");
    while (pos != cwd.npos)
    {
        cwd.replace(pos, 1, "/");
        pos = cwd.find("\\");
    }

	return cwd;
}

  • 作者:mrzhtsu
  • 原文链接:https://blog.csdn.net/mrzhtsu/article/details/125729975
    更新时间:2023年6月21日13:09:40 ,共 254 字。