Thread: random file name

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    random file name

    how would i name the file with a random name?
    i get these errors when i try and compile

    Code:
    10 C:\Documents and Settings\wmorrish\Desktop\New Folder\main.cpp invalid conversion from `int' to `const char*' 
    10 C:\Documents and Settings\wmorrish\Desktop\New Folder\main.cpp    initializing argument 1 of `std::basic_ofstream<_CharT,  
    
    #include <fstream>
    #include <iostream>
    #include <ctime>
    #include <cstdio>
    using namespace std;
    int main()
    {
        srand((unsigned)time(0));
        int name = rand()%3;
        ofstream new_file(name, ios::app);
        new_file << "leval 1" <<endl;
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Reading the error message will give you clues.

    10 is the line number the error was detected on. Then comes the file name, then the error itself. To use the first as an example, you're using an integer where there should be a character-type. name is declared as an integer, and in line 10 you pass it to a function that is expecting a const char* to be specific. Typecast name to a char.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Look up itoa() and/or std::stringstream.

    Also, all this talk about game trainers etc. make me suspicious of your intents (although I could be completely wrong). Do remember that it is against the rules of the CBoard to ask questions regarding hacking, cracking, etc.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    And if you absolutely have to ask questions about it, please make sure you understand the difference between a hacker and a cracker.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. 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
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM