I'm using the code below and I keep getting issues with using strings and the custom class Menu. Any help would be greatly appreciated.
Code:
/*Andrew Smith
*ajs0025
*Menu.cpp
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//modified from your example menu class.
class Menu
{
public:
void printOptions( vector<string> options )
{
for(int i=0;i < options.size(); i++)
{
string option = options.at(i);
cout<< option << endl;
}
}
void addOption( string newOption, vector<string> options){
int j = options.size();
j++;
options.push_back (newOption);
}
//modified from your example "http://www.eng.auburn.edu/~xqin/courses/comp2710/getnumber.cpp"
int getNumber ( int& choice )
{
while ( !( cin >> choice ) ) {
if ( cin.eof() )
return 0;
else {
char ch;
cin.clear();
cout<<"Invalid input, please try again: ";
while (cin.get(ch) && ch != '\n' );
}
}
return choice;
}
private:
vector<string> options;
};
class main
{
Menu test;
string testString;
testString = "this is a test";
test.addOption(testString);
test.printOptions();
};
Comment