A quickie about fstream.h

This is a discussion on A quickie about fstream.h within the C++ Programming forums, part of the General Programming Boards category; This little bit of code: ofstream fout; fout.open("C:\file.txt"); fout <<"Hi"; fout.close(); Will that create the file C:\file.txt and write to ...

  1. #1
    Unregistered
    Guest

    A quickie about fstream.h

    This little bit of code:

    ofstream fout;
    fout.open("C:\file.txt");
    fout <<"Hi";
    fout.close();

    Will that create the file C:\file.txt and write to it? Or will it look for it, and if its created it will write to it? If its the latter, how Do I create it?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    When in doubt just give it a go. The best way to learn is to just give it a try.

    It looks good from here. Your program (assuming you've include <fstream>) will create file.txt in the root of C: and write Hi everytime you run the program. If a file exists named file.txt it will be overwritten.

    For more info on open modes and protection take a look at the ofstream:pen method.

  3. #3
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    Backslash between parenthesis is a escape-sequence sign. F.ex. \n \r \" and so on... To insert a backslash in string you need to write \\. So "C:\\file.txt"
    Making error is human, but for messing things thoroughly it takes a computer

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    25
    I really wish I could find a good tutorial on File IOStreams. I understand a little, just enough to et my self confused.

  5. #5
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    I remember www.google.com gave me some good pages.
    Making error is human, but for messing things thoroughly it takes a computer

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    This website has a basic yet good tutorial on fstream.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  7. #7
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I found this after searching at Google:
    http://gethelp.devx.com/techtips/cpp...0min0601-2.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quickie Linked List Deallocation question.
    By Kurisu in forum C# Programming
    Replies: 4
    Last Post: 06-09-2006, 07:23 AM
  2. Quickie on Arrays...
    By twomers in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2005, 11:13 AM
  3. Quickie: typedef
    By Trauts in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2003, 06:45 PM
  4. quickie pointer question
    By 1337speaker in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2003, 05:55 PM
  5. fstream.h question
    By bluehead in forum C++ Programming
    Replies: 12
    Last Post: 04-13-2002, 01:06 PM

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