Thread: File Loading

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Question File Loading

    My program has to load a file named "x" everytime it is executed.(not from the command line,but from the directory it is in)The first time it is executed there exists no such file,but on the further executions there exists.How can I do this job?

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    //If the file doesn't exist, fstream will create it.


    #include <iostream.h>
    #include <fstream.h>

    int main()
    {
    char buffer[100];

    ifstream FileReader("C:\\whatever.txt");
    FileReader>>buffer;
    cout<<"whatever.txt: "<<buffer<<"\n";
    FileReader.close();

    return 0;
    }
    Last edited by CodeMonkey; 11-22-2001 at 01:41 PM.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM