Thread: Debugging Parse errors

  1. #1
    Registered User
    Join Date
    Feb 2003

    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.

    #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;
       Region township_data[size];
       if(argv[3] == "township.dat")
          read_regions(Region township_data[size], argv[3]);
          read_regions(Region township_data[size], argv[2]);
    int read_regions(Region records[], char filename)
       ifstream infile;   
  "filename", ios::in | ios::binary);
       assert(infile);, sizeof(records));
       return 1;
    Thanks for reading.

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    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

    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 statement. Something about not matching arguments. please help me. As usual, thanks for reading.

    int read_regions(Region records[], char *filename)
       ifstream infile;
   (filename, ios::in | ios::binary);
          return fail;
   , sizeof(records));
             return 1;

    And here are my errors messages: In function `int read_regions(Region*, char*)': 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 =

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >>, 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, 10: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