我想用 2 条不同的路径编写我的程序。所以,我是这样进行的:
std::string path1 = strcat(std::getenv("APPDATA"),"\\myprog.exe") ;
std::string path2 = strcat(std::getenv("APPDATA"),"\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\myprog.exe") ;
当我打印时,我得到:
C:\Users\thispc\AppData\Roaming\myprog.exe
C:\Users\thispc\AppData\Roaming\myprog.exe\Microsoft\Windows\Start Menu\Programs\Startup\myprog.exe
代替 :
C:\Users\thispc\AppData\Roaming\myprog.exe
C:\Users\thispc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\myprog.exe
Dietmar Kühl 的解决方案:
std::string path1 = std::getenv("APPDATA") + std::string("\\myprog.exe");
Oliver Charlesworth 的解释:
strcat()
改变第一个变量