1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// ispunct example (C++)
#include <iostream> // std::cout
#include <string> // std::string
#include <locale> // std::locale, std::ispunct
int main ()
{
std::locale loc;
std::string str="Hello, welcome!";
int cx = 0;
for (std::string::iterator it = str.begin(); it!=str.end(); ++it)
if ( std::ispunct(*it,loc) ) ++cx;
std::cout << "The sentence contains " << cx << " punctuation characters.\n";
return 0;
}
|