Hey guys I have made one program but I need to make it how to calculate whole the characters without the spaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//
#include <iostream>
#include <string>
usingnamespace std;
int main() {
string name_surname=" John Smith";
cout<<"length of your name and surname is:"<<" "<<name_surname.size()<<endl;
return 0;
}
Now John Smith has only 9 charaters but if we calculate spaces then it will show up 11 characters.
So I need a help how to make a string function for a program that will not calculate spaces.
//============================================================================
// Name : Biblioteka.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string>
usingnamespace std;
int main() {
string name_surname=" John Smith ";
int characterCount(std::string in);
int count = 0;
for(unsignedint i = 0, i < in.size(), i++) {
if (!isspace(in[i]))
++count;
}
return count;
cout<<"Length of your name and surname is:"<<" "<<name_surname.size()<<endl;
return 0;
}
Still shows the same errors, even more. Would you like to give it a try by inserting the right functions and code into the whole code and help me out to solve this problem ?
//
#include <iostream>
#include <string>
//<-- insert my code here
int main() {
string name_surname=" John Smith";
cout<<"length of your name and surname is:"<<" "<< characterCount(name_surname)<<endl;
return 0;
}