c# - 如何检索可执行文件的相对路径

标签 c# c++ windows path

<分区>

Possible Duplicate:
How to get the application executable name in Windows (C++ Win32 or C++/CLI)?
Extracting the current executable name

我需要使用 C++ 获取可执行文件目录的相对路径。我用 C# 完成了相同的程序,效果很好。

System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)

我想使用 C++ 获得类似的结果。

最佳答案

使用 boost::文件系统

#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;

int main(int argc, char * argv[])
{
    path p(argv[0]);

    cout << p.parent_path() << endl;

    return 0;
}

关于c# - 如何检索可执行文件的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838726/

相关文章:

c# - 从任务计划程序运行时程序在错误的目录中搜索配置文件

c# - 如何为使用 NPOI 创建的 Excel 中的单元格设置验证

c++ - 模板函数给出编译错误

c++ - 如何在 gcc 或 clang 中使用 c++20(启用模块)包含多个预编译头

windows - 在 Windows 上读取 hid 鼠标/键盘 (hidapi)

c# - 从哪里获得适用于 Windows 的更新 MemCached?

windows - 在Windows中从vim调用外部脚本时如何引用主目录

c# - 强制 session 开始

c# - LINQPad:使用 (.NET4) VS2010 程序集时出现 "BadImageFormatException"?

c++ - C++ 新手,帮助我入门