So how do I implement the getline?
And my problem was that I do not know how to find out spaces newlines and tabs
Okay so I got it done with strings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// Keyboard keys \ |
#include <iostream>
#include <string>
#include <vector>
using std::cout; using std::endl; using std::cin;
using std::string; using std::vector;
int main()
{
string ch; // getting input
unsigned aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0, blankCnt = 0, tabCnt = 0, newlineCnt = 0; // counters
cout << "Type in letters, once finished press CTRL+D/Z (UNIX/WINDOWS)" << endl; // instructions
while (getline(cin, ch))
{
for (auto c : ch)
{
// if its a vowel, increment the appropriate counter
switch (c)
{
case 'a':
++aCnt;
break;
case 'e':
++eCnt;
break;
case 'i':
++iCnt;
break;
case 'o':
++oCnt;
break;
case 'u':
++uCnt;
break;
// Capitals
case 'A':
++aCnt;
break;
case 'E':
++eCnt;
break;
case 'I':
++iCnt;
break;
case 'O':
++oCnt;
break;
case 'U':
++uCnt;
break;
case ' ':
++blankCnt;
break;
case '\t':
++tabCnt;
break;
case '\n':
++newlineCnt;
break;
}
}
}
cout << "Number if vowel a: \t" << aCnt << '\n'
<< "Number of vowel e: \t" << eCnt << '\n'
<< "Number of vowel i: \t" << iCnt << '\n'
<< "Number of vowel o: \t" << oCnt << '\n'
<< "Number of vowel u: \t" << uCnt << '\n'
<< "Number of spaces: \t" << blankCnt << '\n'
<< "Number of tabs: \t" << tabCnt << '\n'
<< "Number of newlines \t" << newlineCnt << endl;
return 0;
}
|
But I do not know how to type a newline in the console.
Could you show me your getline way and how you did it on a char
Last edited on