Thread: File Streams, new error on me.

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    File Streams, new error on me.

    Ive been useing file streams in my projects all along, this is the first time ive used it with MFC.

    here is the error im getting

    "error C2678: binary '>>' : no operator defined which takes a left-hand operand of type 'class ifstream' (or there is no acceptable conversion)"

    And here is a code snippet

    ifstream file(m_filename);
    file >> m_type >> endl; //error on this line

    m_filename is a CString with the name of the file to be opened
    m_type is an int with the value 0;

    The file dose exist, and has only one numer value on the first line.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    7
    Take out the '>> endl'.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    to avoid overlooking the obvious--did you include the fstream header file?

    Otherwise, this might be worth a thought. fstreams take a char * as the argument, not a CString. I suspect CString has a conversion function like c_str() to "convert" a CStrings to a char*. If file is passed something other than a char * it might not allow the fstream to become "functional". This in turn might cause an error such as reported as the compiler might be confusing the >> operator to be a binary shift operator rather than an overloaded extraction operator.

    But I like icegoblin's answer even better.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM