About "fstream" in <fstream.h> and <fstream>

This is a discussion on About "fstream" in <fstream.h> and <fstream> within the C++ Programming forums, part of the General Programming Boards category; I run this is OK, "d.txt" is created and "12" is appended. Code: #include <fstream.h> int main(){ fstream file; file.open( ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    88

    About "fstream" in <fstream.h> and <fstream>

    I run this is OK, "d.txt" is created and "12" is appended.

    Code:
    #include <fstream.h>
    
    int main(){
    	fstream file;
    	file.open( "d.txt", ios::app );
    		file.write( "12" ,2 );
    	file.close();
    	return 0;
    }
    But like this, there will be no effect.
    Code:
    #include <fstream>
    
    using namespace std;
    
    int main(){
    	fstream file;
    	file.open( "d.txt", ios::app );
    		file.write( "12" ,2 );
    	file.close();
    	return 0;
    }
    why? How to do if I must to write in the second form??
    thx.
    Last edited by L.O.K.; 01-08-2005 at 02:28 PM.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,649
    ios::app by itself is not a valid open mode. You need "ios::app | ios::out".

    gg

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    #include <fstream.h>
    If your compiler actually has this file its just for backwards compatibility.
    Code:
    void main(){
    main ALWAYS returns an int

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    Quote Originally Posted by Thantos
    Code:
    #include <fstream.h>
    If your compiler actually has this file its just for backwards compatibility.
    Code:
    void main(){
    main ALWAYS returns an int
    NO, sorry, i use "int main()" in normal times.

    I wrote the "void main()" this time is for quick testing.

    I correct it now.

    thx

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    Quote Originally Posted by Codeplug
    ios::app by itself is not a valid open mode. You need "ios::app | ios:ut".

    gg
    Still can not solve the problem. thx

    I am using MS VC++ 6.

    //==============================//

    It is OK now ~~ sorry for bothering. THANKS .
    Last edited by L.O.K.; 01-08-2005 at 03:12 PM.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I am using MS VC++ 6.
    Get a new compiler. Visual C++ 2005 Express is a free download, so you have no excuse.

    >I wrote the "void main()" this time is for quick testing.
    Get a better compiler and you'll be able to take advantage of the fact that main implicitly returns 0 if you fall off the end. Then using void main would actually take longer because void takes one more keystroke than int. You have no excuse for sloppy code, especially here.

    >#include <fstream.h>
    How this program works is strictly up to the compiler. The C++ standard says nothing about fstream.h, and you shouldn't be using it anyway.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. use <fstream> and ostream overloading together
    By mosu' in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2006, 01:06 PM
  2. <fstream> again !!!!!
    By ElastoManiac in forum C++ Programming
    Replies: 8
    Last Post: 12-19-2005, 02:45 PM
  3. <fstream> arghghghhhhhhhh
    By ElastoManiac in forum C++ Programming
    Replies: 26
    Last Post: 12-02-2005, 05:38 AM
  4. gggrrr, unknown problem with <fstream>
    By axlton in forum C++ Programming
    Replies: 5
    Last Post: 07-25-2003, 11:18 PM
  5. MFC and <fstream>
    By simly01 in forum C++ Programming
    Replies: 3
    Last Post: 08-01-2002, 06:24 AM

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