can't use ofstream argument in header file

This is a discussion on can't use ofstream argument in header file within the C++ Programming forums, part of the General Programming Boards category; hi i have a .h file i dont include anything inside i want to pass a reference to ofstream but ...

  1. #1
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44

    can't use ofstream argument in header file

    hi i have a .h file i dont include anything inside

    i want to pass a reference to ofstream

    but it shows error

    error C2061: syntax error : identifier 'ofstream'

    in the cpp file i include fstream and use namespace std

    is it possible to solve this problem?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,796
    #include <fstream> in the header as well (without that using directive). If you really only need to use std::ostream instead of std::ofstream then you can #include <iosfwd> in the header and #include <ostream> in the source file.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44
    Quote Originally Posted by laserlight View Post
    #include <fstream> in the header as well (without that using directive). If you really only need to use std::ostream instead of std::ofstream then you can #include <iosfwd> in the header and #include <ostream> in the source file.
    thanks a lot it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 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, 01:58 AM

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