std::istream_iterator<std::string> ist(std::cin);
std::istream_iterator<std::string> eof;
std::vector<std::string> str_vec(ist, eof);
std::ofstream ofs("a");
if (!ofs) {
throw std::runtime_error("Open file failed.");
}
std::ostream_iterator<std::string> ost(ofs, "\n");
for (size_t index = 0; index != str_vec.size(); ++index) {
//*ost = str_vec[index];
*ost++ = str_vec[index];
}
私は* ost ++を使用しても同じ結果を得ました。私はistream_iterator増分の意味を知っています。しかし、ostream_iteratorのインクリメントはどのような状況で使用されるべきですか?ostream_iteratorインクリメントはどのような状況で使用する必要がありますか?
ありがとうございます!
なぜ今ostream_iteratorを使うべきかについてはっきりしています。 std :: copyの例をありがとう。 – MasterBeta