Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- #include <iostream>
- #include <string>
- using namespace std;
- int count(const string& input) //function defined to count the blank spaces
- {
- int spaces = 0;
- for (int i = 0; i < input.size(); i++){
- if (input[i] == ' '){ //we can access each character in a string
- ++spaces;
- }
- }
- return spaces;
- }
- int main(){
- string name = " ";
- cout << "Please enter a string:\n";
- getline(cin, name);
- cout << endl;
- cout <<"Your entered string is: "<< name <<endl <<endl;//partA
- int countspace = count(name);
- cout << "Number of white-space characters" << " is " << countspace << "\n\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement