answersLogoWhite

0

Use the following function to count the number of digits in a string.

size_t count_digits (const std::string& str)

{

size_t count = 0;

for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it)

{

const char& c = *it;

if (c>='0' && c<='9');

++count;

}

return count;

}

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

C plus plus program to perform string manipulation?

You do not need to program string manipulation as it is already part of the standard library. See std::string and std::wstring.


C program plus copy of string to another?

strcpy


Do I need to write a program to find a substring in a given string in c plus plus?

No.


What number am I. I am a two digit number You can count to me by 4's plus 3 or by 5's plus 3 What is the smallest number i can be?

23


C plus plus program that will count?

#include int main (void) { puts ("1 2 3"); }


How do you write java programme to find sum of 13 plus 23 plus 33 plus .up to193?

class ass{ public static void main(String[] args ){ int 13,33,23,...193 sum = 0; for (count = 0; count&lt;=193; count++); { sum=sum+count; System.out.print(count + "sum"); }System.out.println("sum is"+sum);


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include&lt;iostream&gt; #include&lt;string&gt; int main() { using namespace std; string s {"Hello world!"}; cout &lt;&lt; s &lt;&lt; endl; }


Write a c plus plus program to read a line from keyboard?

#include &lt;iostream&gt; #include &lt;string&gt; int main() { std::string myStr = ""; std::cout &lt;&lt; std::endl &lt;&lt; "Enter a string: "; std::cin &gt;&gt; myStr; system("PAUSE"); return 0; }


How do you write a counter program to count from 1 to 100 in C plus plus?

for(int i=1; i&lt;=100; ++i ) std::cout &lt;&lt; i &lt;&lt; std::endl;


How can you get a specific string from large string using c plus plus strings?

std::string::substr();


How to write a C plus plus Program to convert a string into an integer?

std::string input = ""; std::getline (std::cin, input); // get input from stdin std::stringstream ss (input); // place input in a string stream integer num = 0; if (ss &gt;&gt; num) // extract integer from string stream { // Success! } else { // Fail! }


1 Write a program to find the length of a string c plus plus?

#include&lt;iostream&gt; #include&lt;string&gt; int main() { std::string s("The quick brown fox jumps over the lazy dog"); std::cout&lt;&lt;s.c_str()&lt;&lt;std::endl; std::cout&lt;&lt;"The previous string is "&lt;&lt;s.size()&lt;&lt;" characters long."&lt;&lt;std::endl; }