Thread: Creating Files

  1. #1
    Seb
    Guest

    Creating Files

    I want to know how to create files in a specific directory, like placing it in exactly C:\Program Files\myfile\w00t.txt, and not just putting it in C:\C compiler\bin\myfile\w00t.txt. so far, i've been using fstream, but i know there are other ways

  2. #2
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Easy! just put C:\Program Files\myfile\w00t.txt instead of w00t.txt...

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    ofstream out( "C:\\Program Files\\myfile\\w00t.txt" );
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    50
    But what if you would make a loop within the program?? Would it create a text file over and over and over and over and over and over again??

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    50

    AND

    What if you would change this:

    ofstream out( "C:\\Program Files\\myfile\\w00t.txt" );

    Into this:

    ofstream out( "C:\\Program Files\\myfile\\w00t.exe" );

    And if the program would be 'evil' and self-replicating.. than.. well, you know what

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it would make it obvious which program was doing it if you did it that way, and it would keep overwriting the same file... you'd have to use a variable that changes with each loop to create mulitple files, and the system would most likely stop it very fast...
    Code:
    ...
    ofstream out;
    int i;
    char filename[256];
    
    for(i=0;i<32000;i++)
    {
       strcpy(filename,"C:\\Program Files\\myfile\\w00t.exe");
       strcat(filename,i);
       strcat(filename,".exe");
    
       out.open( filename,ios::trunc);
       ...
       out.close();
    }
    ...
    i'm not sure if that works, but you could try it... i would make teh loop alot smaller tho...
    Last edited by major_small; 06-15-2003 at 08:16 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  2. creating multiple files
    By lime in forum C Programming
    Replies: 8
    Last Post: 01-01-2004, 02:55 PM
  3. Creating text files
    By Crash1322 in forum C++ Programming
    Replies: 4
    Last Post: 12-15-2003, 09:55 PM
  4. I Need To Know Some Things That I Can Put Into A Batch File
    By TheRealNapster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-20-2003, 08:12 PM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM