Thread: Quiting Program error...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Quiting Program error...

    I'm trying to make a program that asks the user if they wish to quit. but Dev-C++ is giving me this error:

    27 C:\Dev-Cpp\GradeBook.cpp no match for 'operator>>' in 'std::cin >> q'

    here's the code:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    class GradeBook
    {
    public:
           void displayMessage()
           {
            cout << "Welcome to the Grade Book!" << endl;
           }
    };
    
    int main()
    {
     top:
     system("CLS");
    
     GradeBook myGradeBook;
     myGradeBook.displayMessage();
    
     string q[1000000];
     q[0] = "y";
     do
     {
      topOfLoop:
      cout << "\nDo you wish to quit? (y/n): ";
      cin >> q;
      if (q[0] == "n") goto top; 
      if (q[0] == "y") return 1;
      else 
           cout << "That's not a choice!\n\n";
           goto topOfLoop;
     }
     while (q[0] != "y");
     
     return 0;
    }
    I recently changed the array to a string array from a char array. The char array worked a little better but I'm trying to improve the program. Any help?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    If you want to use a string instead of a character array, just make q a string instead of a string[10000000]. Then refer to it as q instead of q[0].

    A character array is used to represent a single string in C. In C++, you need only one instance of the string class.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    Do youself a favour.
    Get rid of the goto statment.

  4. #4
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    uh, that hurts my brain... how about char choice; cin >> choice; .....
    Sorry, but i'm a Code::Blocks man now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM