信奥赛CSP第二轮程序模板。
文件操作代码案例,题目文件夹是 apple
。
在文件夹中创建 apple.in
和 apple.out
分别对应的是输入文件和输出文件。
创建 apple.cpp
是C++程序源文件。参考如下程序。
// 爱码岛编程
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("apple.in", "r", stdin); // 文件中读取
freopen("apple.out", "w", stdout); // 输出到文件
int a, b;
cin >> a >> b; // apple.in 里面的内容
cout << a + b; // 输出到 apple.out 文件中
// 关闭文件
fclose(stdin);
fclose(stdout);
return 0;
}