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

11y 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 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! }


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

std::string::substr();


What is cputs function in computer c plus plus?

Nothing.The C language only recognizes a few keywords, like "for" and "if". Most of what's in a C program ... that doesn't reference routines in the C program itself ... are library calls, and cputs() is one of those. What it does is write its argument (which should be a pointer to a character string) to the console... console put string.


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; }


C program to compute 1 plus 4 plus 9 plus?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int n,count=0,sum=0; printf("Enter the number of values"); scanf("%d",&amp;n); for(int i=1;count&lt;n;i++) { sum+=i*i; count++; } getch(); }


Program to find the occurrences of a given character in a string in c plus plus?

#include#includesize_t count_char (const std::string& s, const char c){size_t count = 0;size_t offset = 0;while ((offset = s.find(c, offset)) != s.npos){++count;++offset;}return count;}int main(){std::string str {"Hello world!"};std::cout


Program that input ten names from user c plus plus?

#include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;string&gt; int main() { std::vector&lt;std::string&gt; names; for (int loop=0; loop!=10;) { std::cout &lt;&lt; ++loop &lt;&lt; " enter a name: "; std::string name; std::cin &gt;&gt; name; names.push_back (name); } }


What is the missing digit in the followingsum275 plus 436 plus 104 plus 72 equals?

There is more than one digit missing.


What is the role of plus operator between two string constant?

The plus operator between string constants allows string concatination: string a = "Hello, "; string b = "World!"; string c = a + b; The output of c would be: "Hello, World!".


Is there a datatype string in c plus plus?

Yes.


Write an interactive c plus plus program to create a linear linked list of customer names their telephone numbers?

#include&lt;list&gt; #include&lt;string&gt; struct Customer { std::string m_name; std::string m_phone; Customer (std::string name, std::string phone): m_name(name), m_phone(phone) {} // ... }; int main() { std::list&lt;Customer&gt; customers; customers.push_back ("Joe Bloggs", "555 7465"); customers.push_back ("Dan Mann", "555 3458"); // ... }