苹果电脑(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++代码了

相关推荐
布莱克6052 小时前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
别问!问就是全会5 小时前
Jupyter Notebook 安装包下载|单元格分块运行,图表直接内嵌
ide·python·其他·jupyter
沫璃染墨6 小时前
从零入门计算机网络系列(十二):HTTP长连接与会话管理详解——从Connection到Cookie与Session
linux·服务器·c++·tcp/ip·ubuntu·http·交互
xiaoye-duck7 小时前
《C++ 项目:手写大模型接入 SDK》DeepSeek接口设计(下):流式响应实现和测试
开发语言·网络·c++·语言模型
旖旎夜光8 小时前
【C++ 基础入门】类和对象(上):封装、对象模型与 this 指针
开发语言·c++·笔记·学习
小超人诞生日记9 小时前
C++ 智能指针的使用及其原理详解
c++·算法
FPGA小迷弟10 小时前
FPGA 与千兆以太网:各类物理接口的形式、区别、使用方法与应用场景详解
tcp/ip·macos·fpga开发·udp·fpga
akinggw10 小时前
libagentcore - 一个基于c++的AI多agent系统升级到2.0版本
开发语言·jvm·c++
繁星蓝雨11 小时前
C++设计原理———多重继承(虚基类、菱形继承、委托、重命名、基类和成员初始化)
c++·委托·多重继承·mi·显式初始化列·虚基类·对象布局
旖旎夜光11 小时前
【C++ 基础入门】命名空间、输入输出、缺省参数与函数重载
开发语言·c++·笔记·学习