Hi all!
Can anyone explain to me why this code is giving me an "illegal use of IOS" error for the fstream objects hexwrite, vowel, and consonant?
Thanks!!
Code:#include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main() { fstream input; input.open("input.txt", ios::in); fstream hexwrite; hexwrite.open("hex.txt", ios::in | ios::out); fstream vowel; vowel.open("vowel.txt", ios::out | ios:in); fstream consonant; consonant.open("consonant.txt", ios::out | ios:in); if (input.fail()) { cout << "Cannot open input.txt"; return -1; } if (hexwrite.fail()) { cout << "Cannotopen hex.txt"; return -1; } if (vowel.fail()) { cout << "Cannot open vowel.txt"; return -1; } if (consonant.fail()) { cout << "Cannot open consonant.txt!"; return -1; } char read, temp; int hexconvert; while (!input.eof()) { input >> read; if (read == 'a' || read == 'e' || read == 'i' || read == 'o' || read == 'u' || read == 'y' || read == 'A' || read == 'E' || read == 'I' || read == 'O' || read == 'U' || read == 'Y') { vowel << read; } else { consonant << read; } hexconvert = read; hexwrite << hex << hexconvert << " "; } int choice=0; while (choice != 5) { cout << "Menu:" << endl << "1) Display contents of input.txt" << endl << "2) Display contents of vowel.txt" << endl << "3) Display contents of consonant.txt" << endl << "4) Display contents of hex.txt" << endl << "5) Quit" << endl << "Choice: "; cin >> choice; switch (choice) { case (1): while (!input.eof()) { input >> read; cout << read; continue; } case (2): while (!vowel.eof()) { vowel >> read; cout << read; continue; } case (3): while (!consonant.eof()) { consonant >> read; cout << read; continue; } case (4): while (!hexwrite.eof()) { hexwrite >> read; cout << read; continue; } } return 0; }



LinkBack URL
About LinkBacks


