Thread: Reading and Writing in C++

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

    Reading and Writing in C++

    how do i read and write a file. Any sample code or tutorial web site would be greatly appreciated.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    ofstream WriteFile;
    WriteFile.open("TestFile.txt", ios::out);
    if(!WriteFile.fail())
    {
       WriteFile << "Hello text-file!";
       WriteFile.close();
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if(!WriteFile.fail())
    I personally prefer to be more explicit in the test I want:

    if ( WriteFile.is_open() )



    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    106
    there is a good tutorial at www.cpp-home.com in tutorials sectinon
    C++ Makes you Feel Better

    "Gravity connot be held reponsible for people falling in love"--Albert Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  2. accessing my com port, writing and reading data
    By shoobsie in forum C Programming
    Replies: 7
    Last Post: 09-16-2005, 03:29 PM
  3. Reading from and writing to same file
    By Strait in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2005, 04:37 PM
  4. file writing and reading
    By Micko in forum C Programming
    Replies: 8
    Last Post: 01-13-2004, 11:18 AM
  5. reading and writing structures to pipes
    By netwizio in forum Linux Programming
    Replies: 3
    Last Post: 01-06-2004, 01:28 AM