C++ Vector to CSV by adding Comma after each element

后端 未结 5 778
梦毁少年i
梦毁少年i 2020-12-18 16:25
vector v;
v.push_back(\"A\");
v.push_back(\"B\");
v.push_back(\"C\");
v.push_back(\"D\");

for (vector::iterator it = v.begin(); it!=v.end()         


        
5条回答
  •  隐瞒了意图╮
    2020-12-18 16:49

    With a normal ostream_iterator, you'll get a comma after every data item -- including the last, where you don't want one.

    I posted an infix_iterator in a previous answer that fixes this problem, only putting commas between the data items, not after the final one.

提交回复
热议问题