苹果电脑(mac系统)安装vscode与配置c++环境,并可以使用万能头文件全流程

写这篇文章是因为有苹果电脑的学生想敲c++代码,所以才写了这篇文章

第一步:

配置mac系统的环境
按住command + 空格 搜索终端打开即可
输入(建议复制粘贴):xcode-select --install
安装完成之后在输入(建议手敲):clang --version
因为我已经安装了,所以显示已经安装了,安装时间大概在5min左右。

第二步:安装VS CODE

Visual Studio Code软件下载地址:https://code.visualstudio.com/
进入官网下载(注意是mac系统)
安装完成打开显示出的界面点击extensions的位置,需要下几个拓展包:

1、Chinese汉化包

安装完成之后注意右下角,点击更换就会重新打开进入汉化的界面

2、code runner

安装完成之后需要实现一些配置,在右边设置这里点击设置

第三个拓展包:c/c++

配置功能(注意位置)

搜索Debug Shortcut

把勾取消掉

现在可以开始写c++代码了

1、新建文件夹(最好不要有中文)

2、创建cpp文件

取名字(我尝试过可以是中文、后缀必须是.cpp)

3、写代码

目前就可以写正常的c++代码了,但是我们需要解决两个问题:

第一个问题:需要终端窗口弹出来:

安装这个拓展

打勾就可以解决在终端窗口的输入输出问题

第二个问题:万能头问题

进入头文件目录
显示 OPEN EDITORS 栏 ,如图勾选 Open Editors(打开编译器) 即可显示
  1. 进入iostream文件
方法1:鼠标右键iostream,点击Go to Definition即可进入;
方法2:按住command后点击iostream即可进入。进入成功后,右侧OPEN EDITORS 栏 可以看到iostream文件。在Finder中打开文件所在位置 。右键点击iostream 文件,选择Reveal in Finder后即可在Finder中打开文件所在位置。
接下来应该进入了一个名字叫v1的文件夹当中,在iostream的同级目录下创建一个新文件夹

添加万能头文件

创建bits文件夹 。在iostream文件所在目录下创建bits文件夹。
之后将iostream文件复制放到bits当中,并修改名字叫bits/stdc++.h
最后打开这个文件夹,将里面代码替换掉,换成下面代码(打开后Ctrl + a全选 删除 在复制粘贴就可)
注意:#include <cstdalign>已经被我注释了,否则会报错
cpp 复制代码
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#if __cplusplus >= 201703L
#include <charconv>
#include <filesystem>
#endif

最后,恭喜你可以在vscode上面写c++代码了

相关推荐
历程里程碑21 分钟前
Linux 库
java·linux·运维·服务器·数据结构·c++·算法
Sheep Shaun23 分钟前
如何让一个进程诞生、工作、终止并等待回收?——探索Linux进程控制与Shell的诞生
linux·服务器·数据结构·c++·算法·shell·进程控制
小龙报39 分钟前
【51单片机】从 0 到 1 玩转 51 蜂鸣器:分清有源无源,轻松驱动它奏响新年旋律
c语言·数据结构·c++·stm32·单片机·嵌入式硬件·51单片机
mailangduoduo1 小时前
零基础教学连接远程服务器部署项目——VScode版本
服务器·pytorch·vscode·深度学习·ssh·gpu算力
石去皿1 小时前
【嵌入式就业6】计算机组成原理与操作系统核心机制:夯实底层基础
c++·面试·嵌入式
王老师青少年编程1 小时前
2024年信奥赛C++提高组csp-s初赛真题及答案解析(完善程序第1题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
一只小小的芙厨1 小时前
AT_tkppc3_d 巨大チェスボード 题解
c++·题解
我在人间贩卖青春1 小时前
C++之继承与派生类的关系
c++·向上造型·向下造型
Trouvaille ~1 小时前
【Linux】应用层协议设计实战(二):Jsoncpp序列化与完整实现
linux·运维·服务器·网络·c++·json·应用层
EmbedLinX2 小时前
嵌入式之协议解析
linux·网络·c++·笔记·学习