mlimber wrote:
Denis Petronenko wrote:
Hello,
for(int i=0; i<100; ++i){
cout << i << ",";
}
// how can i remove last comma here?
.....
cout << endl;
Use an if statement in the for-loop. If you're on the last iteration,
don't print one.
Cheers! --M
ok. lets see on following example.
i want to print elements of set divided by comma:
set<intmyset;
for(int i=0; i<10; ++i) myset.insert(random());
for_each(myset.begin(),myset.end(),printint());
i defined function object to do this job:
class printint
{
public:
printint(){}
~printint(){
// remove last comma here
cout << endl;
}
void operator()(int val){
cout << val << ",";
}
};
How can i remove or not write last comma here? function object don't
know how many elements stored in myset.
Thanks.