【保姆级教程】VSCode上搭建C/C++开发环境(Windows系统)

本文将为您详细介绍如何在Windows系统上使用Visual Studio Code(VSCode)搭建C/C++开发环境。我们将从安装VSCode、安装编译器、配置调试器等环节进行详细讲解,让您轻松上手C/C++编程。
一、安装Visual Studio Code

  1. 访问VSCode官网(https://code.visualstudio.com/),下载并安装适用于Windows系统的VSCode。
  2. 启动VSCode,您可能需要登录Microsoft账户。
    二、安装C/C++编译器
  3. 下载MinGW-w64(http://mingw-w64.org/)或Visual C++ Build Tools(https://visualstudio.microsoft.com/visual-cpp-build-tools/)。
  4. 安装过程中,请确保选择安装C/C++编译器和相关工具。
    三、配置VSCode的C/C++环境
  5. 打开VSCode,点击左侧扩展按钮,搜索并安装“C/C++”扩展。
  6. 安装完成后,点击左侧“C/C++”图标,打开“C_Cpp.json”配置文件。
  7. 在“C_Cpp.json”文件中,填写以下配置:
{
    "compilerPath": "path/to/mingw64/bin/g++.exe",
    "includePath": [
        "path/to/mingw64/x86_64/include",
        "path/to/mingw64/x86_64/include/c++",
        "path/to/your/custom/include"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "cStandard": "c11",
    "cppStandard": "c++17",
    "intelliSenseMode": "gcc-x64"
}

请将上述配置中的“path/to/mingw64/bin/g++.exe”替换为您的MinGW-w64编译器路径,将“path/to/mingw64/x86_64/include”替换为您的MinGW-w64头文件路径,如果需要,还可以添加自定义的头文件路径。
四、配置调试器

  1. 打开VSCode,点击左侧“调试”图标,打开“launch.json”配置文件。
  2. 在“launch.json”文件中,填写以下配置:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++ Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb",
            "logging": { "trace": false, "traceResponse": false, "engineLogging": false }
        }
    ]
}

五、编写、编译和调试C/C++程序

  1. 在VSCode中新建一个C/C++文件,例如“hello.c”。
  2. 在“hello.c”文件中编写以下代码:
#include <stdio.h>
int main() {
    printf("Hello, World!");
    return 0;
}
  1. 保存文件,并按下F5键运行程序。您可以选择调试模式启动程序,以查看调试信息。
  • 9
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个基于Python的BBS论坛保姆教程,适用于Windows操作系统。 首先,你需要安装Python和一些必要的库。推荐使用Anaconda或Miniconda,因为它们包含了常用的Python库。在命令行中输入以下命令来安装Flask和SQLAlchemy: ``` pip install Flask pip install SQLAlchemy ``` 接下来,你需要创建一个Flask应用程序。在你的工作目录中创建一个名为`app.py`的文件,并输入以下代码: ```python from flask import Flask, render_template, request, redirect, url_for from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///bbs.db' db = SQLAlchemy(app) class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) content = db.Column(db.Text) author = db.Column(db.String(50)) def __repr__(self): return '<Post %r>' % self.title @app.route('/') def index(): posts = Post.query.all() return render_template('index.html', posts=posts) @app.route('/post/<int:id>') def post(id): post = Post.query.get(id) return render_template('post.html', post=post) @app.route('/new_post', methods=['GET', 'POST']) def new_post(): if request.method == 'POST': title = request.form['title'] content = request.form['content'] author = request.form['author'] post = Post(title=title, content=content, author=author) db.session.add(post) db.session.commit() return redirect(url_for('index')) return render_template('new_post.html') if __name__ == '__main__': app.run(debug=True) ``` 这个应用程序使用了Flask和SQLAlchemy,定义了一个名为`Post`的数据库模型,并创建了三个路由函数。`index`函数会渲染主页,`post`函数会渲染帖子页面,`new_post`函数会渲染新帖子页面,并将新帖子添加到数据库中。 接下来,你需要创建模板。在你的工作目录中创建一个名为`templates`的文件夹,并在其中创建三个HTML文件:`index.html`、`post.html`和`new_post.html`。 `index.html`模板: ```html <!doctype html> <html> <head> <title>BBS</title> </head> <body> <h1>BBS</h1> <ul> {% for post in posts %} <li><a href="{{ url_for('post', id=post.id) }}">{{ post.title }}</a> by {{ post.author }}</li> {% endfor %} </ul> <a href="{{ url_for('new_post') }}">New Post</a> </body> </html> ``` `post.html`模板: ```html <!doctype html> <html> <head> <title>{{ post.title }}</title> </head> <body> <h1>{{ post.title }}</h1> <p>{{ post.content }}</p> <p>by {{ post.author }}</p> <a href="{{ url_for('index') }}">Back to Index</a> </body> </html> ``` `new_post.html`模板: ```html <!doctype html> <html> <head> <title>New Post</title> </head> <body> <h1>New Post</h1> <form method="post"> <label for="title">Title:</label> <input type="text" id="title" name="title"><br><br> <label for="content">Content:</label> <textarea id="content" name="content"></textarea><br><br> <label for="author">Author:</label> <input type="text" id="author" name="author"><br><br> <input type="submit" value="Submit"> </form> <a href="{{ url_for('index') }}">Back to Index</a> </body> </html> ``` 最后,你需要创建一个SQLite数据库。在命令行中输入以下命令: ``` python from app import db db.create_all() exit() ``` 现在你可以运行应用程序了。在命令行中输入以下命令: ``` python app.py ``` 然后在浏览器中访问`http://localhost:5000`即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小柒笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值