-
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?
-
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.
-
Do youself a favour.
Get rid of the goto statment.
-
uh, that hurts my brain... how about char choice; cin >> choice; .....