confused........

This is a discussion on confused........ within the C++ Programming forums, part of the General Programming Boards category; hello everyone, I'm working on this project about using input/output files, and I got this long compile error that I ...

  1. #1
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25

    confused........

    hello everyone,

    I'm working on this project about using input/output files, and I got this long compile error that I don't understand.....

    could anyone give me some insights??

    Thanks so much!!

    here are the errors and part of the code

    errors:


    prog4.cc: In function `int main()':
    prog4.cc:51: no match for `_IO_ostream_withassign & >> string &'
    /usr/local/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/../../../../include/g++-3
    /std/bastring.cc:434: candidates are: class istream & operator >><char, string_c
    har_traits<char>, __default_alloc_template<false,0> >(istream &, basic_string<ch
    ar,string_char_traits<char>,__default_alloc_templa te<false,0> > &)
    prog4.cc:57: parse error before `,'
    prog4.cc:59: no match for `ostream & >> string &'
    /usr/local/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/../../../../include/g++-3
    /std/bastring.cc:434: candidates are: class istream & operator >><char, string_c
    har_traits<char>, __default_alloc_template<false,0> >(istream &, basic_string<ch
    ar,string_char_traits<char>,__default_alloc_templa te<false,0> > &)
    prog4.cc: In function `float CalculatePremium(int, char, basic_string<char,strin
    g_char_traits<char>,__default_alloc_template<false ,0> >)':
    prog4.cc:86: ANSI C++ forbids comparison between pointer and integer
    prog4.cc:182: ANSI C++ forbids comparison between pointer and integer


    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    
    
    float CalculatePremium (int age, char gender, string type_coverage); 	
    				//function prototype
    
    int main()
    {
      string first_name;            //declare string variable first name
      string last_name;             //declare string variable last name
      string gender;                //declare string variable gender
      int age;                      //declare int variable age
      string type_coverage;         //declare string variable type of coverage
      string club_member;		//declare string variable health club member
      string smoker;		//declare string variable smoker
      int zip_code;                 //declare int variable zip code
      int premium;			//declare int variable premium
    
      ifstream inFile;		//declare file streams
      ofstream outFile;
      inFile.open("inputdata");	//opens the file 
      if(!inFile)
      {
        cout << "Input file failed!" << endl;
        return 1;			//terminates the program if input fails
      }
     
      
      inFile >> first_name >> last_name >> gender >> age >> type_coverage >> 
      club_member >> smoker >> zip_code; 	//assigns input values from inFile
      
      cout >> first_name >> last_name >> gender >> age >> type_coverage >> 
      club_member >> smoker >> zip_code; 	//echos the input on the monitor
      
      while (inFile)			//looping in capturing & processing input data
      {
        premium = CalculatePremium (int age, char gender, string type_coverage);
        outFile << first_name >> last_name >> type_coverage >> zip_code 
        >> premium ; 			//output premium to file "output" 
        
        inFile >> first_name >> last_name >> gender >> age >> type_coverage >> 
        club_member >> smoker >> zip_code; 	//assigns input values to inFile
    
        outFile.open("output");		//creates output data
      }
      outFile.open("output");
      if(!outFile)
      {
        cout << "Output file failed!" << endl;
        return 1;			//terminates the program if output fials
      }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >> - This means in.
    << - This means out.

    They are not interchangeable. These are the biggest problems, I have no doubt that you can find the rest, the other error messages are quite straightforward.

    -Prelude
    My best code is written with the delete key.

  3. #3
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25

    Talking

    Hi Prelude,

    Thanks so much for the post.... once again I got thrown off by the long complicated error messages that I didn't even realize I had the < > signs switched...

    I do have other questions though, what does the error message mean by "pointer"? And is there any index/appendix somewhere that I could find a glossary of common error codes?

    Thanks so much!

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    as for the sign switch prob...try to copy and paste as least you could, errors like that tend to come up...

    as for the pointer errors, you are doing an illegal comparison within your function, which i assume is under main...

    error messages are dependent on errors and are usually self explanatory, also, compiler differences come into play with how the error message may be worded...

  5. #5
    JCK
    JCK is offline
    Registered User
    Join Date
    Oct 2002
    Posts
    25
    alpha, thanks for the post...

    I've been looking for a better editor than pico that will show line number for each line of codes so it will be much easier for me to debug since the program is getting bigger and bigger and I can't sit there counting lines...

    are there any out there that comes with the regular Micorsoft programs?? I'm using this book by Dale and Weems:

    "Programming and Problem Solving with C++, 3rd edition" and it comes with a disk. I downloaded and tried to use the editor and it doesn't have the line number either... (I won't be suprised to know that I'm missing something again )

    Or are there some good editors out there are free for downloading from teh internet??

    Thanks so much, this board has been a great help for a biginer like me........

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you could try bloodshed dev-c++, www.bloodshed.net

    or quincy, i use quincy2000, www.alstevens.com/quincy.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused with array size
    By desmond5 in forum C Programming
    Replies: 4
    Last Post: 12-04-2007, 04:14 PM
  2. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 12:13 AM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 10:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21