4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++で複数の数値データをcsvに出力する。part1

Last updated at Posted at 2019-09-12

毎回、数値データを出力するたびに忘れてしまうので、メモ
今回は、列数が2つのデータをつかうため、std::pairを使うが、3つ以上の列数を使う場合、pairではなく、tupleを使えばよい

output.cpp

#include <iostream>
#include <fstream>
#include <vector>
#include <utility>

int main()
{
//出力したいファイル名を指定する
	std::ofstream outputfile("test.csv");

	std::vector<std::pair<int,int>>data;
//出力したいデータを作る
	data.push_back(std::make_pair(1,3));
	data.push_back(std::make_pair(4, 3));
	data.push_back(std::make_pair(1, 2));
//データの出力
	for (auto &&b : data) {
		outputfile << b.first;
		outputfile << ',';
		outputfile << b.second;
		outputfile << '\n';
	}
//ファイルの出力
	outputfile.close();
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?