loop exit

i want to ask how to exit the program by pressing Enter key.

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
  // C++ program to count occurrences of a given

// character

#include <iostream>

#include <string>

using namespace std;



// Function that return count of the given

// character in the string

int countLetterInString(string phase , char c)

{

    // Count variable

    int cnt = 0;



    for (int i=0;i<phase.length();i++)



        // checking character in string

      {



       if (phase[i] == c)

            cnt++;}



    return cnt;

}



// Driver code

int main()

{
    char c;
    cout <<"This program counts number of specific characters in phrase."<<endl;
    string str;
    cout <<"Enter the phrase or hit Enter key to stop: ";
    while(getline(cin, str)){
    if( ??? )
    {
        break;
    }
else
   {
    cout << "Enter character to count in phrase: "; cin>>c;

    cout <<"There are "<< countLetterInString(str, c)<<" "<<c<<" in the phrase" << endl;
   }
    }
    return 0;

}


can you guys help me which is need to be written in (???) so that when entering Enter key it will exit the programm
why are you using a while loop?

you could just say getline(cin,str)
Topic archived. No new replies allowed.