C++新文件模板

1.普通模板

#include<bits/stdc++.h>
using namespace std;

#define infile "infile.in"
#define outfile "outfile.out"
#define cin_cout_f
#define speedup
#undef cin_cout_f
#undef speedup

#ifdef cin_cout_f
#define cin _____in_____
#define cout _____out_____
ifstream _____in_____(infile);
ofstream _____out_____(outfile);
#else
#ifdef speedup
void spup(){
	ios::sync_with_stdio(false);
	cin.tie(0);
}
#endif
#endif

ostream& operator<<(ostream& os, __int128 num) {
	if (num < 0) {
		os << '-';
		num = -num;
	}
	if (num > 9) {
		os << static_cast<__int128>(num / 10);
	}
	os << static_cast<int>(num % 10);
	return os;
}

istream& operator>>(istream& is, __int128& num) {
	num = 0;
	bool negative = false;
	char ch;
	while (is.get(ch) && isspace(ch)) {
		
	}
	if (ch == '-') {
		negative = true;
	} else {
		num = ch - '0';
	}
	while (is.get(ch) && isdigit(ch)) {
		num = num * 10 + (ch - '0');
	}
	if (negative) {
		num = -num;
	}
	if (is) {
		is.unget();
	}
	return is;
}

int main(){
#ifndef cin_cout_f
#ifdef speedup
	spup();
#endif
#endif
	
	return 0;
}

2.DevCpp模板

把这个模板复制进代码模板里
image

#include<bits/stdc++.h>
using namespace std;

#define infile "%REPL_BEGIN%infile.in%REPL_END%"
#define outfile "%REPL_BEGIN%outfile.out%REPL_END%"
#define cin_cout_f
#define speedup
%REPL_BEGIN%#undef cin_cout_f%REPL_END%
%REPL_BEGIN%#undef speedup%REPL_END%

#ifdef cin_cout_f
#define cin _____in_____
#define cout _____out_____
ifstream _____in_____(infile);
ofstream _____out_____(outfile);
#else
#ifdef speedup
void spup(){
	ios::sync_with_stdio(false);
	cin.tie(0);
}
#endif
#endif

ostream& operator<<(ostream& os, __int128 num) {
	if (num < 0) {
		os << '-';
		num = -num;
	}
	if (num > 9) {
		os << static_cast<__int128>(num / 10);
	}
	os << static_cast<int>(num % 10);
	return os;
}

istream& operator>>(istream& is, __int128& num) {
	num = 0;
	bool negative = false;
	char ch;
	while (is.get(ch) && isspace(ch)) {
		
	}
	if (ch == '-') {
		negative = true;
	} else {
		num = ch - '0';
	}
	while (is.get(ch) && isdigit(ch)) {
		num = num * 10 + (ch - '0');
	}
	if (negative) {
		num = -num;
	}
	if (is) {
		is.unget();
	}
	return is;
}

int main(){
#ifndef cin_cout_f
#ifdef speedup
	spup();
#endif
#endif
	%INSERT%
	return 0;
}

3.其他实现看这

  1. 文件输入输出
  2. 彩色打印
posted @ 2025-01-18 12:23  Gavinbeta  阅读(71)  评论(0)    收藏  举报