ofstream help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ofstream help

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    ofstream help

    i have 3 files
    main.cpp
    functions.cpp
    header.h
    the main.cpp contains only the open and close ofstream functions for the text file.
    the functions.cpp output ofstream line to the text file
    header.h just contains what they always contain.

    where do i put ofstream outf; (for example) and include<fstream>
    so that the main and function cpps can identify the "outf << " or "outf"

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,640

    Re: ofstream help

    pass the ostream object created in main to the functions by reference.

    Code:
    void foo(ostream & out)
    {
       out << "whatever\n";
    }
    
    
    
    int main()
    {
        ofstream outfile("out.txt");
        foo(outfile);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center