简体   繁体   English

如何添加 GetCurrentDirectory 文件? C++ [已解决]

[英]how do I add a GetCurrentDirectory file? C++ [solved]

Question, how do I add a GetCurrentDirectory file?问题,如何添加 GetCurrentDirectory 文件? I have this code:我有这个代码:

const unsigned long maxDir = 260;
         char currentDir [maxDir] = "";
         GetCurrentDirectory (maxDir, currentDir);
std :: cout << currentDir << std :: endl;

ok but if I want to add a file std :: cout << currentDir + "mydll.dll" << std :: endl;好的,但如果我想添加一个文件 std::cout << currentDir + "mydll.dll" << std :: endl;

it gives me an error.它给了我一个错误。

How can I include the current directory + the file?如何包含当前目录+文件?

It is to inject a dll.就是注入一个dll。

LPCSTR DllPath = currentDir + "mydll.dll"; LPCSTR DllPath = currentDir + "mydll.dll";

Thank you so much.非常感谢。

solution: You must use strcpy() and strcat() for C-style strings.解决方案:您必须对 C 样式字符串使用 strcpy() 和 strcat()。 Alternatively, you can use std::string, which would allow you to use the + operator in the way that you intended或者,您可以使用 std::string,这将允许您按照预期的方式使用 + 运算符

Thanks a lot: Andreas Wenzel非常感谢:Andreas Wenzel

I think you are missing by the actual path.我认为您错过了实际路径。 You should do like below(if it is a Linux) "CurrentDir/FileName" std :: cout << currentDir + "\\" + "mydll.dll" << std :: endl;你应该像下面这样(如果它是一个 Linux) "CurrentDir/FileName" std :: cout << currentDir + "\\" + "mydll.dll" << std :: endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM