c&c++ 的window环境获取exe文件所在的目录

发布时间 2023-04-19 11:22:01作者: 米歪歪

#include <iostream>
#include<stdio.h>
#include <direct.h>
#include <windows.h>
#include<process.h>
#include <atlstr.h>

char
buff[MAX_PATH];//用于存放获取的路径信息。 GetModuleFileName(NULL, buff, MAX_PATH); CString str2 = buff; int pos = str2.ReverseFind('\\');//查找倒数最后一个“\\”符号 str2 = str2.Left(pos + 1); //删除最后一个\后面的字符 cout << str2 << endl;