Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cctype>
- using namespace std;
- int GetNumOfCharacters(const string usrStr) {
- int count = 0;
- for (int i = 0; i < usrStr.length(); i++) {
- if (usrStr[i]!=' ' or usrStr[i]!='\t') {
- count++;
- }
- }
- return count;
- }
- void OutputWithoutWhiteSpace(const string usrStr) {
- cout << "String with no whitespace: ";
- for (int i = 0; i < usrStr.length(); i++) {
- if (usrStr[i] != ' ' and usrStr[i] != '\t') {
- cout << usrStr[i];
- }
- }
- }
- int main() {
- int count;
- string usrStr;
- cout << "Enter a sentence or phrase:"<<endl;
- getline(cin, usrStr);
- cout << endl;
- cout << "You entered: " << usrStr << endl;
- cout << endl;
- count = GetNumOfCharacters(usrStr);
- cout << "Number of characters: " << count<<endl;
- OutputWithoutWhiteSpace(usrStr);
- cout<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment