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

相关推荐
迷途之人不知返6 分钟前
C++初识(3)
c++
weixin_446260857 分钟前
解锁 React 开发新体验!Puck - 智能可视化编辑器
前端·react.js·编辑器
claider33 分钟前
Vim User Manual 阅读笔记 usr_12.txt Clever tricks 花招
笔记·编辑器·vim
王老师青少年编程43 分钟前
2024年9月GESP真题及题解(C++七级): 矩阵移动
c++·算法·题解·真题·gesp·七级·矩阵移动
txinyu的博客1 小时前
连接池问题
服务器·网络·c++
我发在否1 小时前
OpenResty > Lua断点调试
vscode·lua·断点·openresty·luapanda
初願致夕霞1 小时前
实现具备C++11现代特性的STL——list篇(使用shared_ptr智能指针实现,解决了循环引用问题)
c++·list
雾岛听蓝1 小时前
AVL树实现
开发语言·c++
苏宸啊1 小时前
C++模版template(泛型编程)初阶
c++
郝学胜-神的一滴1 小时前
Qt自定义TabWidget:实现左侧标签与水平文本布局
开发语言·c++·qt·程序人生