A little problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 23
Reputation: WesFox13 is an unknown quantity at this point 
Solved Threads: 0
WesFox13 WesFox13 is offline Offline
Newbie Poster

A little problem

 
0
  #1
Nov 5th, 2008
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.
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
  1. ///
  2. ///
  3. /// Wesley Montgomery
  4. /// 11/05/2008
  5. /// CS 210
  6. /// Prof. Gelotte
  7. /// Section A (9:30-10:20)
  8.  
  9. // THIS IS PROGRAM 4 (ISBN-Check), a program that verifies ISBN numbers.
  10.  
  11. #include <iostream>
  12. #include <fstream> // REQUIRED FOR FILE STREAMS
  13. #include <cstdlib> // FOR DEFINITION OF EXIT_FAILURE
  14. #include <cctype>
  15. #include <string>
  16. using namespace std;
  17.  
  18. // ASSOCIATE STREAMS WITH EXTERNAL FILE NAMES
  19. #define inFile "isbntest.txt" // LINKED ISBN FILE (LIST) SOURCE
  20.  
  21. // FUNCTIONS USED
  22. void menuPrompt (); // MAIN MENU USER INSTRUCTION
  23. void userVal (); // MANUAL INPUT VALIDATION
  24. int readFile (); // LINKED FILE VALIDATION
  25. bool isbnCheckForUser (string isbn); // ISBN VALIDATION FUNCTION FOR USER INPUT
  26. bool isbnCheckForFile (string isbn); // ISBN VALIDATION FUNCTION FOR FILE INPUT
  27.  
  28. int main ()
  29. {
  30. char choice; // INPUT-MAIN MENU CHOICE
  31. string isbn;
  32.  
  33. do
  34. {
  35. menuPrompt ();
  36. cin >> choice;
  37. switch (choice)
  38. {
  39. case '1':
  40. userVal ();
  41. break;
  42. case '2':
  43. readFile ();
  44. break;
  45. case '3':
  46. cout << "Thank you for using ISBN-Check. Have a nice day!" << endl;
  47. break;
  48. default:
  49. cerr << "Oops! Incorrect selection. Please try again." << endl;
  50. }
  51. }
  52. while (choice != '3');
  53.  
  54. system ("pause");
  55.  
  56. return 0;
  57. }
  58.  
  59. void menuPrompt ()
  60. {
  61. cout << "Welcome to ISBN-Check." << endl;
  62. cout << "This program will verify the format of your ISBN(s)." << endl;
  63. cout << "To manually input the ISBN(s), enter 1." << endl;
  64. cout << "To verify the ISBN(s) from the linked .txt file, etner 2." << endl;
  65. cout << "When you're done, enter 3 to exit the program." << endl;
  66. }
  67.  
  68. void userVal ()
  69. {
  70. char subchoice; // INPUT- SUB MENU CHOICE
  71. string isbn; // INPUT- ISBN STRING
  72. do
  73. {
  74. cout << "Enter an ISBN:";
  75. cin >> isbn;
  76. isbnCheckForUser (isbn);
  77. if (isbnCheckForUser (isbn) == true)
  78. cout << "This is a valid ISBN." << endl;
  79. else
  80. cout << "This is NOT a valid ISBN." << endl;
  81. cout << endl;
  82. cout << "To go back to the main menu, enter 1." << endl;
  83. cout << "To continue manually inputting ISBN(s), enter any digit besides 1." << endl;
  84. cin >> subchoice;
  85. }
  86. while (subchoice != '1');
  87.  
  88. }
  89.  
  90. int readFile ()
  91. {
  92. ifstream fin;
  93. string isbn;
  94. fin.open (inFile);
  95. if (fin.fail ())
  96. {
  97. cerr << " ERROR: Cannot open " << inFile << " for input. " << endl;
  98. return EXIT_FAILURE; // FAILURE RETURN
  99. }
  100. fin >> isbn;
  101. isbnCheckForFile (isbn);
  102. if (isbnCheckForFile (isbn) == true)
  103. cout << "This is a valid ISBN." << endl;
  104. else
  105. cout << "This is NOT a valid ISBN." << endl;
  106.  
  107. }
  108.  
  109. bool isbnCheckForUser (string isbn)
  110. {
  111. int isbn0;
  112. int isbn1;
  113. int isbn2;
  114. int isbn3;
  115. int isbn4;
  116. int isbn5;
  117. int isbn6;
  118. int isbn7;
  119. int isbn8;
  120. int isbn9;
  121. int sum;
  122. int modulo;
  123.  
  124. if (isbn.at(0) == '-' || isbn.at(isbn.length()-1) == '-')
  125. cout << "This is NOT a valid ISBN." << endl;
  126.  
  127. isbn.find('-');
  128. isbn.erase('-');
  129. isbn.at(0) = isbn0;
  130. isbn.at(1) = isbn1;
  131. isbn.at(2) = isbn2;
  132. isbn.at(3) = isbn3;
  133. isbn.at(4) = isbn4;
  134. isbn.at(5) = isbn5;
  135. isbn.at(6) = isbn6;
  136. isbn.at(7) = isbn7;
  137. isbn.at(8) = isbn8;
  138. isbn.at(9) = isbn9;
  139.  
  140. if (isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X')
  141. isbn9 = 10;
  142.  
  143. sum= isbn0 * 1 + isbn1 * 2 + isbn2 * 3 + isbn3 * 4 + isbn4 * 5 + isbn5 * 6 + isbn6 * 7 + isbn7 * 8 + isbn8 * 9;
  144. modulo = sum / 11;
  145.  
  146. if (modulo = 10 && isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X')
  147. cout << "This is a valid ISBN." << endl;
  148.  
  149. else if (modulo = 10 && isbn.at(isbn.length()-1) != 'x' || isbn.at(isbn.length()-1) != 'X')
  150. cout << "This is NOT a valid ISBN." << endl;
  151.  
  152. else if (modulo != isbn9)
  153. cout << "This is Not a valid ISBN." << endl;
  154.  
  155. else
  156. cout << "This is a valid ISBN." << endl;
  157. }
  158.  
  159. bool isbnCheckForFile (string isbn)
  160. {
  161. ifstream fin;
  162. int num_of_isbn;
  163. int count;
  164. int isbn0;
  165. int isbn1;
  166. int isbn2;
  167. int isbn3;
  168. int isbn4;
  169. int isbn5;
  170. int isbn6;
  171. int isbn7;
  172. int isbn8;
  173. int isbn9;
  174. int sum;
  175. int modulo;
  176.  
  177. getline(istream& fin, string& num_of_isbn, char '\n');
  178. fin.ignore( 80, '\n');
  179. while (!fin.eof())
  180. {
  181. for (count=0; count < num_of_isbn; count++)
  182. {
  183. getline (fin, isbn);
  184. if (isbn.at(0) == '-' || isbn.at(isbn.length()-1) == '-')
  185. cout << "This is NOT a valid ISBN." << endl;
  186. isbn.find('-'); //HOW DO I COUNT THE NUMBER OF DASHES?
  187. isbn.erase('-');
  188. isbn.at(0) = isbn0;
  189. isbn.at(1) = isbn1;
  190. isbn.at(2) = isbn2;
  191. isbn.at(3) = isbn3;
  192. isbn.at(4) = isbn4;
  193. isbn.at(5) = isbn5;
  194. isbn.at(6) = isbn6;
  195. isbn.at(7) = isbn7;
  196. isbn.at(8) = isbn8;
  197. isbn.at(9) = isbn9;
  198. if (isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X')
  199. isbn9 = 10;
  200. sum= isbn0 * 1 + isbn1 * 2 + isbn2 * 3 + isbn3 * 4 + isbn4 * 5 + isbn5 * 6 + isbn6 * 7 + isbn7 * 8 + isbn8 * 9;
  201. modulo = sum / 11;
  202. if (modulo = 10 && isbn.at(isbn.length()-1) == 'x' || isbn.at(isbn.length()-1) == 'X')
  203. cout << "This is a valid ISBN." << endl;
  204. else if (modulo = 10 && isbn.at(isbn.length()-1) != 'x' || isbn.at(isbn.length()-1) != 'X')
  205. cout << "This is NOT a valid ISBN." << endl;
  206. else if (modulo != isbn9)
  207. cout << "This is Not a valid ISBN." << endl;
  208. else
  209. cout << "This is a valid ISBN." << endl;
  210. }
  211. }
  212. }
Last edited by WesFox13; Nov 5th, 2008 at 2:25 pm. Reason: inserted rest of code
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,810
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: A little problem

 
0
  #2
Nov 5th, 2008
  1. 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:

  1. 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?

  1. fin >> num_of_isbn;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC