windows上mingw和vscode的相对路径问题



我在vscode打开的文件夹中处理文件有问题。我不能指定文件的相对路径,因为它是编译器的相对路径,而不是我的项目文件夹的相对路径。例如:

//I want to write in this way
std::ofstream out("out.txt"); //*compiler's folder*out.txt
//But have to write in this way
std::ofstream out("*full path to file in working folder*\out.txt")

包含也是同样的问题。有什么办法可以解决吗?

好的,我自己找到了修复方法。我的PATH没有添加g++ bin文件夹,所以我添加了它,并将"command": "*path to g++.exe*/g++.exe"更改为"command": "g++",并将"options": { "cwd": "*path to g++ bin folder*" },删除为tasks.json。现在我编译的工作空间是"main"。相对路径是正确的。谢谢drescherjm的帮助。

最新更新