Debugging Parse errors

This is a discussion on Debugging Parse errors within the C++ Programming forums, part of the General Programming Boards category; I am trying to compile the following code, and I keep getting parse errors. Can someone please tell me what ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    11

    Debugging Parse errors

    I am trying to compile the following code, and I keep getting parse errors. Can someone please tell me what these errors are, and what may be wrong with my code that I am getting them.

    Code:
    #include <iostream>
    #include <fstream>
    #include <cassert>
    using namespace std;
    
    const int size = 100;
    
    typedef struct Region
       {
       int code;
       char name_township[60];
       char name_state[20];
       char name_county[20];
       };
    
    int read_regions(Region records[], char filename);
    
    int main(int argc, char *argv[])
       {                               
       if(argc !=3)
          {
          cout << "This program needs 2 command line arguments" << endl;
          exit(0);
          }
    
       Region township_data[size];
    
       if(argv[3] == "township.dat")
          read_regions(Region township_data[size], argv[3]);
       else
          read_regions(Region township_data[size], argv[2]);
       }
    
    int read_regions(Region records[], char filename)
       {
       ifstream infile;   
    
       infile.open("filename", ios::in | ios::binary);
       assert(infile);
       infile.read(records, sizeof(records));
    
       infile.close();
       return 1;
       }
    Thanks for reading.

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    In read_regions file name should be a char* or char[] not a char... and you should actually use it =)

    And what are the specific errors?
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    11

    My modified code; still need help

    Ok, I found the error, it's in my function, and I've modified it a little, and am still getting errors, but I know where the errors are: the errors are in the infile.read() statement. Something about not matching arguments. please help me. As usual, thanks for reading.

    Code:
    int read_regions(Region records[], char *filename)
       {
       ifstream infile;
    
       infile.open (filename, ios::in | ios::binary);
    
       if(!infile)
          return fail;
       else            
             {
             infile.read(records, sizeof(records));
             return 1;
             }
       }
    :

    And here are my errors messages:
    assign1.cc: In function `int read_regions(Region*, char*)':
    assign1.cc:40: no matching function for call to `std::basic_ifstream<char,
    std::char_traits<char> >::read(Region*&, unsigned int)'
    /opt/gcc-3.2/include/c++/3.2.1/bits/istream.tcc:778: candidates are:
    std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
    _Traits>::read(_CharT*, int) [with _CharT = char, _Traits =
    std::char_traits<char>]

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>infile.read(records, sizeof(records));

    The prototype for read() is:
    >>istream &read( char *buffer, streamsize num );
    Do you think that records is a char* ?
    Also, sizeof(records) won't work, as records is a pointer, therefore its size will be the size of the pointer, not what it points to.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  2. string ?
    By cogeek in forum C Programming
    Replies: 27
    Last Post: 12-05-2004, 09:45 PM
  3. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. help with errors...
    By Gamma in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2002, 07:11 PM

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