C++;:获取路径';复制对象并打印它们 我对C++很陌生,所以请不要评判。 我需要的是获取以下路径对象,然后打印它们
我的路径:C++;:获取路径';复制对象并打印它们 我对C++很陌生,所以请不要评判。 我需要的是获取以下路径对象,然后打印它们,c++,file,directory,path,C++,File,Directory,Path,我的路径:Server>跟踪>…一些文件…,.sln和所有其他文件位于Server目录下 这是我的密码。没有显示错误,但是当我试图打印这个目录时,我什么也没有得到。怎么了 // Takes the full path of the current directory and changes windows' path separation style from \ to / std::string Server::WindowsPathToForwardSlashes() { char
Server>跟踪>…一些文件…
,.sln和所有其他文件位于Server
目录下
这是我的密码。没有显示错误,但是当我试图打印这个目录时,我什么也没有得到。怎么了
// Takes the full path of the current directory and changes windows' path separation style from \ to /
std::string Server::WindowsPathToForwardSlashes()
{
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
std::string::size_type fullPath = std::string(buffer).find_last_of("\\/");
std::string windowsPath = std::string(buffer).substr(0, fullPath) + "\\tracks\\*";
std::vector<std::string> spitList;
std::string fixedPath;
std::vector<std::string> splittedStrings = Split(windowsPath, '\\');
// split windows' path
for (int i = 0; i < splittedStrings.size(); i++)
{
//std::cout << splittedStrings[i] << std::endl;
spitList.push_back(splittedStrings[i]);
}
// reassemble the path with forward slashes
for (std::vector<std::string>::const_iterator i = spitList.begin(); i != spitList.end(); ++i)
{
fixedPath += *i + "/";
//std::cout << fixedPath << std::endl;
}
fixedPath = fixedPath.substr(0, fixedPath.size() - 1);
return fixedPath;
}
//获取当前目录的完整路径,并将windows的路径分隔样式从\更改为/
std::string Server::WindowsPathToForwardSlashes()
{
字符缓冲区[最大路径];
GetModuleFileName(空,缓冲区,最大路径);
std::string::size\u type fullPath=std::string(缓冲区);
std::string windowsPath=std::string(buffer).substr(0,完整路径)+“\\tracks\\*”;
std::向量表;
std::字符串固定路径;
std::vector splittedStrings=Split(窗口路径“\\”);
//拆分窗口的路径
对于(int i=0;i //std::cout使用std::filesystem::path::generic\u string
怎么样?Split(windowsPath,\\\);
——如果这个代码应该返回std::string
的向量,为什么以后(int i=0;i,字符串不是已经存在了吗“拆分”为一个向量?另外,fixedPath=fixedPath.substr(0,fixedPath.size()-1);
--如果您只需使用fixedPath.pop_back()
没有显示错误——如果你是指编译器错误,那么这意味着代码没有语法错误——这与程序的逻辑是否正确无关。--但是当我试图打印此目录时,我什么也看不到。--我看不到“打印”"语句。请在您发布的代码中的任意位置发布一个。@EEORIKA,在调用GetModuleFileName
后,buffer
在哪一行中是否包含期望值?有两个版本的GetModuleFileName
,具体取决于编译程序时使用的字符集。您的程序假定它正在使用GetModuleFileNameA
。这是我开始调查问题的地方。我会继续逐步检查程序,直到遇到与我预期不同的东西。