Thread: Files!

  1. #1
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294

    Files!

    i want to know how do u open . write files in c++
    i know in c
    need to know the code line of c++
    for ex: in 'c' u say
    fopen(FILE,"w") //wite mode
    how would i say this in c++

  2. #2
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403
    Code:
    #include <fstream>
    
    ifstream infile("Filename goes here");
    ofstream outfile("Filename goes here");
    infile would be the file you read from, outfile the file you write to.

  3. #3
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294
    ok,
    so wat r ios::xx used for and how?

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    They are different modifying options. For example, ios::nocreate will not create a file if it does not exist. If not there, a file will be created if it doesn't exist.

  5. #5
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294
    could u give me a simple code that would create a file binary file in C++

  6. #6
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    similer question

    when i read a file its just brings up the hax value like 0xFFFFFF
    what do i do to make it display the file contentsin stead

  7. #7
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294
    basically i do this

    #define FILE "myfile.ext"
    FILE *mf;

    main()

    ifstream inmf("myfile.ext", ios::binary);
    // so this is gona open/create a file in binary mode, right?

    ok after that line i want to write something to file how would i do that
    like in c you do
    fwrite(.....);
    but how in C++
    this time ans people!!!!
    dont make me mad%*#U*4

  8. #8
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163
    dude theres a whole tutorial on file io on this website
    +++
    ++
    + Sekti
    ++
    +++

  9. #9
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    You can't write to files using ifstream, you have to use ofstream.
    Then you can call ofstream::write(buffer, length);

    More information can be found at http://msdn.microsoft.com/library/de..._Functions.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM