VScode读文件总是不能成功,结果发现路径和用visual studio读文件时不一样,想必是配置的时候出了问题吧。先贴一个C++显示当前目录的代码:
#include
#include
#include "stdlib.h"
#include
using namespace std;
int main()
{
char cwd[256];
_getcwd(cwd, 256);
cout << cwd << endl;
char* path;
if ((path = _getcwd(NULL, 0)) == NULL) {
cerr << "Error message : _getcwd error"<< endl;
}
else {
cout << path << endl;
}
}
然后运行发现是编译器位置而不是工程位置。

网上提出修改launch.json中的cwd当前目录,但是这个连debug的一起修改了,导致debug失败,报错ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-
暂时性的解决办法是使用绝对路径,或者手动进行路径的转换。以后有空研究一下如何在配置中解决问题。