Calculate the number of characters in the string in c

How to count the number of “_” in a string like “bla_bla_blabla_bla”?
#include 

std::string s = "a_b_c ";
size_t n = std::count(s.begin(), s.end(),'_');

How to calculate like ” The number of “_” in a string like bla_bla_blabla_bla”?

#include 

std::string s = "a_b_c";
size_t n = std:: count(s.begin(), s.end(),'_');

Leave a Comment

Your email address will not be published.