C/C++ 通用代码模板


✅ C 语言代码模板(main.c

适用于基础项目、算法竞赛或刷题:

c 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

// 宏定义区
#define MAX_N 1000
#define INF 0x3f3f3f3f

// 函数声明
void solve();

int main() {
    // 快速读写(可选)
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    solve();
    return 0;
}

void solve() {
    // 示例:读取两个整数并输出和
    int a, b;
    printf("请输入两个整数:");
    scanf("%d %d", &a, &b);
    printf("它们的和是:%d\n", a + b);
}

✅ C++ 代码模板(main.cpp

适用于算法题、开发任务或初学者练习:

cpp 复制代码
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <limits>
#include <iomanip>

using namespace std;

// 宏定义(可选)
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int INF = 1e18;
const int MOD = 1e9 + 7;

// 函数声明
void solve();

int32_t main() {
    fastio;
    solve();
    return 0;
}

void solve() {
    // 示例:读取两个整数并输出它们的乘积
    int a, b;
    cout << "请输入两个整数:" << endl;
    cin >> a >> b;
    cout << "它们的乘积是:" << a * b << endl;
}
相关推荐
apocelipes9 分钟前
C++20新增属性[[no_unique_address]]详解
c++·性能优化
澡点睡觉10 分钟前
【golang长途旅行第38站】工厂模式
开发语言·后端·golang
Dxy123931021612 分钟前
Dockerfile文件常用配置详解
开发语言·docker
MATLAB代码顾问14 分钟前
MATLAB可以实现的各种智能算法
开发语言·matlab
77qqqiqi22 分钟前
学习结构体
c语言·学习
十五年专注C++开发38 分钟前
cargs: 一个轻量级跨平台命令行参数解析库
linux·c++·windows·跨平台·命令行参数解析
宁静致远202139 分钟前
【C++设计模式】第二篇:策略模式(Strategy)--从基本介绍,内部原理、应用场景、使用方法,常见问题和解决方案进行深度解析
c++·设计模式·策略模式
王伯安呢1 小时前
Java开发环境配置入门指南
java·开发语言·jvm·eclipse·环境搭建·新手
学习噢学个屁1 小时前
基于STM32智能阳台监控系统
c语言·stm32·单片机·嵌入式硬件
·前路漫漫亦灿灿1 小时前
C++-类型转换
开发语言·c++