How to remove the last comma from the end of string in C++

1 Answer

0 votes
#include <iostream>

int main() {
    std::string s = "c,c++,java,python,";
    
    s[s.size() - 1] = 0;

    std::cout << s;
}




/*
run:

c,c++,java,python

*/

 



answered Apr 12, 2022 by avibootz

Related questions

1 answer 253 views
1 answer 231 views
1 answer 290 views
1 answer 252 views
1 answer 238 views
2 answers 328 views
2 answers 342 views
...