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;
}
相关推荐
W_326009 分钟前
Python文件进阶:一维数据与 CSV 文件读写
开发语言·python
Tyler_TXZ24 分钟前
C++C语言之——二叉树
c语言·开发语言·数据结构·c++·二叉树
小羊先生car35 分钟前
F429-HAL-RS485(回环/双机实验)(2026/8/16)
c语言·单片机·嵌入式硬件·软件构建
不会代码的小猴1 小时前
C++新增关键字
开发语言·c++·笔记
yaoxin5211231 小时前
497. Java 反射 - 使用反射读取注解
java·开发语言·python
2019一路前行1 小时前
Python 函数式编程
开发语言·python
liulilittle2 小时前
并发与内存安全术语:定义、分类与关联
c++·安全·并发·术语
_wyt0012 小时前
从图到树:9道洛谷基础题带你入门树形结构
c++·
冯汉栩2 小时前
Swift Control View,Label渐变颜色(源码)
开发语言·ios·swift
Titan20243 小时前
Linux网络基础知识
linux·服务器·网络·c++·学习