This may help--
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
class customerClass {
string masterArray[2][255];
public:
void getActions(int);
void saveInArray(int, string);
string readArray(int,int);
};
string customerClass::readArray(int x, int y) {
cout << masterArray[x][y];
}
void customerClass::saveInArray(int a, string sx) {
switch(a) {
case 1:
masterArray[a][0] = sx;
break;
}
}
void customerClass::getActions(int actions) {
stringstream ss (stringstream::in | stringstream::out);
string uInput;
switch(actions) {
case 1:
cout << "Options: (2) Add Name, (3) Add Address, (0) Exit: ";
break;
case 2:
cout << "Customer Name ";
cin >> uInput;
ss << uInput;
saveInArray(1,ss.str());
break;
case 3:
cout << "Customer Address: ";
cin >> uInput;
ss << uInput;
break;
default:
// exit(1);
break;
}
}
int main() {
customerClass rect;
int n;
do {
rect.getActions(1);
cin >> n;
if(cin.fail()){
cout << "bad input!" << endl;
cin.clear();
cin.ignore(INT_MAX, '\n');
continue;
}
rect.getActions(n);
}while(n!=0);
return 0;
}
You're probably wondering why I bothered with the sstream?
Consider the potential problem with bad input for the input buffer, cin.
You can pass information from cin to another buffer. That way if
you encounter extraction problems, its no longer cin's responsibility
to handle it - its that of the buffer that you are performing extraction on!
I personally, never like messing with cin directly. Using temporary buffers
can simplify problems with the standard input buffer at the cost of space
in your program.