C++の入出力ファイル サンプル

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(){
ifstream ifs;
ofstream k;
ofstream q;
int x;
for (int i = 1; i < 4; i++){
ifs.open("test.txt");
k.open("aa" + to_string(i) + ".txt");
for (int j = 0; j < 3; j++){
ifs >> x;
k << i*x << endl;
}
ifs.close();
k.close();
ifs.open("test.txt");
q.open("q" + to_string(i) + ".txt");
for (int j = 0; j < 3; j++){
ifs >> x;
q << i * 2 * x << endl;
}
ifs.close();
q.close();
}
return 0;
}

g++ example.cpp -std=c++11


Makefile example

test:testfile
./testfile
testfile: test.cpp
g++ test.cpp -std=c++11 -o testfile




0 件のコメント:

コメントを投稿

AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards

https://beta.atcoder.jp/contests/abc044/tasks/arc060_a すべてのカードからaを引く 平均がa⇔和がa になる mapを使って各カードが何枚ずつ有るか記録する。 カードがn種類あるとすると、 0<=i...