#include<iostream>
#include<string>
size_t count_spaces(std::string& str)
{
size_t spaces=0;
for(size_t i=0; i<str.size(); ++i)
if( str[i]==32 )
++spaces;
return( spaces );
}
int main()
{
std::string str("This is a string with some spaces.");
size_t spaces = count_spaces(str);
std::cout<<"The string ""<<str.c_str()<<"" has "<<spaces<<" spaces.\n"<<std::endl;
}
Chat with our AI personalities
.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
This is not a question.
what is string
i dont no string for servlate