LoginSignup
10
10

More than 5 years have passed since last update.

C++で配列の内容を出力するを3種

Posted at

vector array{0,1,2,3};

0
1
2
3

みたいに表示したい。

  1. 普通にforで
   for ( vector<int>::iterator i=begin(array); i!=end(array); ++i ) {
      std::cout << i << std::endl;
   }
  1. C++11のラムダ式とeachで
   std::each(begin(array), end(array), [&](int i){ std::cout << i << std::end }
  1. std::copyとstd::ostream_iteratorを使う。
   std::copy(begin(array), end(array), std::ostream_iterator<int>(std::cout, "\n"));

こんな書き方あるんだ、へーって思ったけど直感的じゃないから使わないかな…。

ostream_iterator、istream_iterator 覚えたら便利そう…(たぶん覚えない)。
http://en.cppreference.com/w/cpp/iterator/ostream_iterator

10
10
1

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
10
10