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;
}
相关推荐
charlie1145141913 分钟前
AwesomeQt:最小的Qt6系列迷你版本教程发布!
linux·c++·qt·c
『昊纸』℃9 分钟前
C语言程序设计从入门到进阶【比特鹏哥c语言2023完整版视频教程】(c语言基础入
c语言·函数·常量·编程教程·变量作用域
Run_Teenage19 分钟前
Linux:线程互斥,线程锁
运维·开发语言·jvm
小小de风呀21 分钟前
de风——【从零开始学C++】(四):类和对象(下)
开发语言·c++·算法
覆东流22 分钟前
第10天:python元组
开发语言·后端·python
CSCN新手听安24 分钟前
【Qt】系统相关(一)内容简介,事件概念,事件的处理
开发语言·c++·qt
不想写代码的星星36 分钟前
重识 std::tuple:一个被低估的编译期异构容器
开发语言·c++
techdashen1 小时前
用 Rust 写生产级服务要踩多少坑——Cloudflare 把答案做成了一个开源库
开发语言·rust·开源
码界奇点1 小时前
基于Python的微信公众号爬虫系统设计与实现
开发语言·爬虫·python·毕业设计·web·源代码管理
瞎折腾啥啊1 小时前
VCPKG详细使用教程
linux·c++·cmake·cmakelists