Three Forms to Print a Vector

vector<string> svec{"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "red", "turtle"};
ostream_iterator<string> out_iter(cout, " ");
// The first form
for (auto e : svec)
{
	cout << e << " ";
}
cout << endl;
// The second form
for (auto e : svec)
{
	*out_iter++ = e;
}
cout << endl;
// The third form
copy(svec.begin(), svec.end(), out_iter);
cout << endl;

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

5 × 3 =

85 + = 93