[注:由于之前服务器发生过故障,管理员密码被改了我一直不知道谁有管理员权限,所以一些配置不能实现,所以本文我只是在我的阿里云服务器上测试了远程C++的编写与调试]在服务器端需要安装的工具包括:sshg++gdbCMake本地VS Code安装的插件包括:
然后在本地VS Code中
随便配置一个远程账号即可,类似于XShell。
选择一个远程的文件夹作为项目的目录。然后按F1创建一个新项目:
项目构建目录如下:
包含编译运行等按钮。附上一段测试代码,主要作用就是在Linux端读取hello.txt并将内容进行打印输出:
#include #include #include #include #include using namespace std;int main(int argc, char **argv){ cout << "path" << argv[0]<<endl; //打开一个文件,自己人以构建即可 int fd = open("/home/runxuan/VS_Code_Project/hello.txt", O_RDWR); //如果文件打开失败推出 if (fd == -1) { cerr << "error \n"; return 0; } //读取文件 while (true) { //构建一个读取缓冲区 char buffer[1024]; //开始读取数据 ssize_t length = read(fd, buffer, sizeof(buffer)); //读取完毕退出循环 if (length == 0) { break; } //加上文件结尾 buffer[length] = '\0'; cout << buffer << endl; } //关闭数据流 close(fd); return 0;}