How can I remove the last comma from a loop in C++ in a simple way?

后端 未结 6 1340
梦毁少年i
梦毁少年i 2020-12-06 13:31

This program is for printing prime numbers till the input given and separating every prime number with a comma.

void main(){

    int N, counter=0, isPrime;
         


        
6条回答
  •  醉话见心
    2020-12-06 14:09

    To easily remove the last comma you can use the '\b' character.

    for(auto item : vec)
        std::cout << item << ", " ;
    std::cout << "\b\b " << std::endl;
    

提交回复
热议问题