| | |
A little problem
![]() |
•
•
Join Date: May 2008
Posts: 23
Reputation:
Solved Threads: 0
Hey all I've been writing a program that cheks an ISBN number as valid or invalid as an assignment for a class but I need a little bit of help. I get these errors when I try to compile it:
error C2275: 'std::string' : illegal use of this type as an expression
error C2275: 'std::istream' : illegal use of this type as an expression
error C2062: type 'char' unexpected
and the complier says this is the line repsonsible for the error.
these are the only errors I have in my program
Any help on this problem?
Here's the full code
error C2275: 'std::string' : illegal use of this type as an expression
error C2275: 'std::istream' : illegal use of this type as an expression
error C2062: type 'char' unexpected
and the complier says this is the line repsonsible for the error.
getline(istream& fin, string& num_of_isbn, char '\n'); these are the only errors I have in my program
Any help on this problem?
Here's the full code
C++ Syntax (Toggle Plain Text)
/// /// /// Wesley Montgomery /// 11/05/2008 /// CS 210 /// Prof. Gelotte /// Section A (9:30-10:20) // THIS IS PROGRAM 4 (ISBN-Check), a program that verifies ISBN numbers. #include <iostream> #include <fstream> // REQUIRED FOR FILE STREAMS #include <cstdlib> // FOR DEFINITION OF EXIT_FAILURE #include <cctype> #include <string> using namespace std; // ASSOCIATE STREAMS WITH EXTERNAL FILE NAMES #define inFile "isbntest.txt" // LINKED ISBN FILE (LIST) SOURCE // FUNCTIONS USED void menuPrompt (); // MAIN MENU USER INSTRUCTION void userVal (); // MANUAL INPUT VALIDATION int readFile (); // LINKED FILE VALIDATION bool isbnCheckForUser (string isbn); // ISBN VALIDATION FUNCTION FOR USER INPUT bool isbnCheckForFile (string isbn); // ISBN VALIDATION FUNCTION FOR FILE INPUT int main () { char choice; // INPUT-MAIN MENU CHOICE string isbn; do { menuPrompt (); cin >> choice; switch (choice) { case '1': userVal (); break; case '2': readFile (); break; case '3': cout << "Thank you for using ISBN-Check. Have a nice day!" << endl; break; default: cerr << "Oops! Incorrect selection. Please try again." << endl; } } while (choice != '3'); system ("pause"); return 0; } void menuPrompt () { cout << "Welcome to ISBN-Check." << endl; cout << "This program will verify the format of your ISBN(s)." << endl; cout << "To manually input the ISBN(s), enter 1." << endl; cout << "To verify the ISBN(s) from the linked .txt file, etner 2." << endl; cout << "When you're done, enter 3 to exit the program." << endl; } void userVal () { char subchoice; // INPUT- SUB MENU CHOICE string isbn; // INPUT- ISBN STRING do { cout << "Enter an ISBN:"; cin >> isbn; isbnCheckForUser (isbn); if (isbnCheckForUser (isbn) == true) cout << "This is a valid ISBN." << endl; else cout << "This is NOT a valid ISBN." << endl; cout << endl; cout << "To go back to the main menu, enter 1." << endl; cout << "To continue manually inputting ISBN(s), enter any digit besides 1." << endl; cin >> subchoice; } while (subchoice != '1'); } int readFile () { ifstream fin; string isbn; fin.open (inFile); if (fin.fail ()) { cerr << " ERROR: Cannot open " << inFile << " for input. " << endl; return EXIT_FAILURE; // FAILURE RETURN } fin >> isbn; isbnCheckForFile (isbn); if (isbnCheckForFile (isbn) == true) cout << "This is a valid ISBN." << endl; else cout << "This is NOT a valid ISBN." << endl; } bool isbnCheckForUser (string isbn) { int isbn0; int isbn1; int isbn2; int isbn3; int isbn4; int isbn5; int isbn6; int isbn7; int isbn8; int isbn9; int sum; int modulo; if (isbn.at(0) == '-' || isbn.at(isbn.length()-1) == '-') cout << "This is NOT a valid ISBN." << endl; isbn.find('-'); isbn.erase('-'); isbn.at(0) = isbn0; isbn.at(1) = isbn1; isbn.at(2) = isbn2; isbn.at(3) = isbn3; isbn.at(4) = isbn4; isbn.at(5) = isbn5; isbn.at(6) = isbn6; isbn.at(7) = isbn7; isbn.at(8) = isbn8; isbn.at(9) = isbn9; if (isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X') isbn9 = 10; sum= isbn0 * 1 + isbn1 * 2 + isbn2 * 3 + isbn3 * 4 + isbn4 * 5 + isbn5 * 6 + isbn6 * 7 + isbn7 * 8 + isbn8 * 9; modulo = sum / 11; if (modulo = 10 && isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X') cout << "This is a valid ISBN." << endl; else if (modulo = 10 && isbn.at(isbn.length()-1) != 'x' || isbn.at(isbn.length()-1) != 'X') cout << "This is NOT a valid ISBN." << endl; else if (modulo != isbn9) cout << "This is Not a valid ISBN." << endl; else cout << "This is a valid ISBN." << endl; } bool isbnCheckForFile (string isbn) { ifstream fin; int num_of_isbn; int count; int isbn0; int isbn1; int isbn2; int isbn3; int isbn4; int isbn5; int isbn6; int isbn7; int isbn8; int isbn9; int sum; int modulo; getline(istream& fin, string& num_of_isbn, char '\n'); fin.ignore( 80, '\n'); while (!fin.eof()) { for (count=0; count < num_of_isbn; count++) { getline (fin, isbn); if (isbn.at(0) == '-' || isbn.at(isbn.length()-1) == '-') cout << "This is NOT a valid ISBN." << endl; isbn.find('-'); //HOW DO I COUNT THE NUMBER OF DASHES? isbn.erase('-'); isbn.at(0) = isbn0; isbn.at(1) = isbn1; isbn.at(2) = isbn2; isbn.at(3) = isbn3; isbn.at(4) = isbn4; isbn.at(5) = isbn5; isbn.at(6) = isbn6; isbn.at(7) = isbn7; isbn.at(8) = isbn8; isbn.at(9) = isbn9; if (isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X') isbn9 = 10; sum= isbn0 * 1 + isbn1 * 2 + isbn2 * 3 + isbn3 * 4 + isbn4 * 5 + isbn5 * 6 + isbn6 * 7 + isbn7 * 8 + isbn8 * 9; modulo = sum / 11; if (modulo = 10 && isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X') cout << "This is a valid ISBN." << endl; else if (modulo = 10 && isbn.at(isbn.length()-1) != 'x' || isbn.at(isbn.length()-1) != 'X') cout << "This is NOT a valid ISBN." << endl; else if (modulo != isbn9) cout << "This is Not a valid ISBN." << endl; else cout << "This is a valid ISBN." << endl; } } }
Last edited by WesFox13; Nov 5th, 2008 at 2:25 pm. Reason: inserted rest of code
•
•
Join Date: Jan 2008
Posts: 3,757
Reputation:
Solved Threads: 491
C++ Syntax (Toggle Plain Text)
getline(istream& fin, string& num_of_isbn, char '\n');
This isn't a function call. It's a function prototype already defined in C++, so you don't need to define it. Leave the variable types out. The compiler will figure out what the types are and what function to call:
C++ Syntax (Toggle Plain Text)
getline (fin, num_of_isbn, '\n');
This would be a proper function call. It won't work in your program because you have
num_of_isbn defined as an integer in line 162 above. You have to read it into a string or char* and then convert it to an integer if you want to use this getline function. I don't know what your input file looks like, but is there a reason you aren't doing this? C++ Syntax (Toggle Plain Text)
fin >> num_of_isbn;
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the C++ Forum
- Previous Thread: Put picture before ListViewItem
- Next Thread: CIN>>EQUATION (how to then mult by it later)
| Thread Tools | Search this Thread |
api application array based binary bitmap c# c++ c/c++ char class classes code coding compile compression console conversion count cpm delete deploy deque desktop developer dialog directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer introductory java lib linkedlist linkednodes linker loop looping loops map math matrix memory multiple news node numbertoword output parameter pointer problem program programming project python random read recursion reference rpg security sorting string strings temperature template test text text-file tree url variable vector video whyisthiscodecausingsegmentationfault win32 windows winsock wordfrequency wxwidgets






