写这篇文章是因为有苹果电脑的学生想敲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(打开编译器) 即可显示
- 进入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++代码了
