目标:使用g++和vscode编译运行多个cpp文件
知识点
-
include尖括号和双引号区别:https://blog.csdn.net/qq_27825451/article/details/102568482
代码结构如下
utils.cpp
#include <iostream>
using namespace std;
void print(string str)
{
cout << str << endl;
}
utils.h
#include <iostream>
using namespace std;
void print(string str);
main.cpp
#include <iostream>
#include "utils.h"
using namespace std;
int main()
{
string s = "hello world";
print(s);
}
g++编译多个文件
参考
-
https://blog.csdn.net/chen_z_p/article/details/105352547
-
https://blog.csdn.net/wohu1104/article/details/110734326
方法1
方法2
vscode编译多个文件
使用的是vscode远程连接ubuntu
tasks.json 原有基础上修改如下
launch.json 原有基础上修改如下