I'm trying to figure out how to use istream for taking input for a class. We barely talked about it in class and my teacher didn't give us so much as an example or explanation.
#include <iostream>
#include <string>
#include "Header.h"
usingnamespace std;
int main(){
Alcohol selection;
string input;
int choice;
//select which alcohol they have
cout << "Enter 1 for Vodka, 2 for Beer.\n";
cin >> choice;
selection.setType(choice);
cout << selection.getType() << endl;
//if they choose vodka, get vodkas characteristics and output them
if(selection.getType() == "Vodka"){
Vodka vodka;
cout << "What is the flavor of vodka?\n";
//cin >> vodka.setFlavor();
istream& operator>>(istream& ifs, Vodka& vodka);
ifs >> vodka.setFlavor();
cout << "What percentage alcohol is it?\n";
//cin >> vodka.setPercent();
cout << "You have " << vodka.getFlavor() << "flavored " << selection.getType() << " that is " << vodka.getPercent << "% alcohol.\n";
}
elseif(selection.getType() == "Beer")
Beer beer;
else
cout << "ERROR!\n";
system("PAUSE");
return 0;
}
It say ifs is undefined. The one istream example from him:
istream& operator >> (istream& if, complex &c)
complex being class name, c being initialized as that class, if should be something else since "if" is a reserved word.
Will gladly take all constructive criticisms since I need it to learn. Thanks much!
Thank you so much! I was looking for examples and was having a hard time finding any. After playing with it for a bit and reading that I figured it out!