I am currently implementing a text-file based testing UI that will take mocked up user inputs from a text file (line-by-line) to simulate real user input instead of using std::cin
.
The issue arises when I attempt to pass std::cin
into std::ifstream
parameter; the issue persists whether it is by reference or by value.
Function:
void ZoinkersEngine::displayMainMenu(User& currentUser, std::ifstream& in) {
//need a function to check the role level of the user here
//DEMO (Mock-up) of Menu
std::string option = "";
do {
std::cout << std::string(40, '\n');
std::cout << "Successfully logged in...\n\n\n";
std::cout << "Main Menu:\n";
std::cout << "[0] Order Plan\n";
std::cout << "[1] Generate Plan\n\n";
std::cout << "Please input number of selected option: ";
// std::cin >> option;
in >> option;
if (option == "0") {
currentUser.calculateExhibitFav(zoinkersDirectory);
currentUser.orderPlan(zoinkersDirectory);
}
else if (option == "1") {
currentUser.calculateExhibitFav(zoinkersDirectory);
currentUser.generatePlan(zoinkersDirectory);
}
else if (option == "cancel" || option == "Cancel") {
break;
}
} while (option != "cancel" || option != "Cancel");}
Call To Function:
engine.displayMainMenu(currentUser, std::cin);
Error:
cannot convert argument 2 from 'std::istream' to 'std::ifstream'
I can not figure this out; as far as I know ifstream
is derived from the istream
base class, thus the compiler should be able to cast it.
EDIT #1: Current IDE is Visual Studios 2017; answers must also compile on g++ and work on linux.