I know how to do this in other languages, but not in C ++, which I have to use here.
I have a set of lines that I print in a list and they need a comma between each, but not a trailing comma. For example, in java, I would use a string constructor and just remove the comma from the end after I built my string. How to do it in C ++?
auto iter = keywords.begin(); for (iter; iter != keywords.end( ); iter++ ) { out << *iter << ", "; } out << endl;
At first I tried to insert this block to do this (moving the comma here)
if (iter++ != keywords.end()) out << ", "; iter--;
I hate it when little things touch me.
EDIT: Thanks to everyone. That is why I post such things here. So many good answers and are decided differently. After the Java semester and assembly (different classes), the need to complete a C ++ project in 4 days threw me into a loop. I not only got my answer, I got the opportunity to think about different ways to solve such a problem. Tall.
c ++ pretty-print
quandrum Aug 16 '10 at 20:18 2010-08-16 20:18
source share