Q:

As a somewhat more complicated example, we’ll use a range for and the ispunct function to count the number of punctuation characters in a string

0

As a somewhat more complicated example, we’ll use a range for and the ispunct function to count the number of punctuation characters in a string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

string s("Hello World!!!");
// punct_cnt has the same type that s.size returns; see § 2.5.3 (p. 70)
decltype(s.size()) punct_cnt = 0;
// count the number of punctuation characters in s
for (auto c : s) // for every char in s
if (ispunct(c)) // if the character is punctuation
++punct_cnt; // increment the punctuation counter
cout << punct_cnt<< " punctuation characters in " << s << endl;

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now