Generating files with different names at runtime

Vishal Sharma

Vishal Sharma

@vishal-pysGmK Oct 17, 2024
hi everyone!
I'm working on project which Generates certificates for different students.
The interface takes the input of Name, College, Secured position and generates the certificate...
but I want to generate all the certificates at once. So, to avoid overlapping of the file names, i want to generate different file names during runtime like c1,c2,c3 etc.. Is there any way to do it??
Thanks!

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Nov 7, 2012

    What language you are using?
    Generate file using <Student_id>_<FileName>.
  • Vishal Sharma

    Vishal Sharma

    @vishal-pysGmK Nov 7, 2012

    ianoop
    What language you are using?
    Generate file using <Student_id>_<FileName>.
    oh... forgot to mention that!! i'm programming it in C++
  • rahul69

    rahul69

    @rahul69-97fAOs Nov 7, 2012

    Vishal0203
    oh... forgot to mention that!! i'm programming it in C++
    Then it is quite simple😉
    • Take a file name e.g. Student, so ur files will be named like student1,student2 etc.
    • Run a loop for the no. of students.
    • Append the index name with the file name to create final file name.
    • Append this final file name with ".txt" or whatever format u want.
    • Using this final file name create the new file.
    • Write to that file and close that file
    In this process take care that u first convert index to string before appending/concatinating with the file name to get the final file name.😁
  • Vishal Sharma

    Vishal Sharma

    @vishal-pysGmK Nov 7, 2012

    what if i want to rename the file during runtime??? I mean, after manipulating the things in file (which is already existing), i want to rename it and save it as different file so that the overlapping of main file doesn't occur!!
  • grsalvi

    grsalvi

    @grsalvi-7IhIh1 Nov 7, 2012

    Vishal0203
    what if i want to rename the file during runtime??? I mean, after manipulating the things in file (which is already existing), i want to rename it and save it as different file so that the overlapping of main file doesn't occur!!
    After editing a existing file if you want to save to new file with new name :

    create a function which creates two fstreams , one for input and another for output.

    create appropriate name for destination file (you may append source file name with temp.txt).
    use input file stream to read the source file ,and out put the content as it is to destination file as it is.

    After successful copying if you want to delete source file,use system command :
    delete with the file name.
  • Vishal Sharma

    Vishal Sharma

    @vishal-pysGmK Nov 8, 2012

    grsalvi
    After editing a existing file if you want to save to new file with new name :

    create a function which creates two fstreams , one for input and another for output.

    create appropriate name for destination file (you may append source file name with temp.txt).
    use input file stream to read the source file ,and out put the content as it is to destination file as it is.

    After successful copying if you want to delete source file,use system command :
    delete with the file name.
    That's a very big procedure.. I got it in an easier way! 😀 I used c_str() and got it!
    Thanks everyone!!
  • rahul69

    rahul69

    @rahul69-97fAOs Nov 8, 2012

    Vishal0203
    That's a very big procedure.. I got it in an easier way! 😀 I used c_str() and got it!
    Thanks everyone!!
    Could u please explain a little more as how did u renamed the file using c_str()?? As far as I know c_str is used for conversion of string object into character array,so how did u used it for renaming?
  • Vishal Sharma

    Vishal Sharma

    @vishal-pysGmK Nov 8, 2012

    rahul69
    Could u please explain a little more as how did u renamed the file using c_str()?? As far as I know c_str is used for conversion of string object into character array,so how did u used it for renaming?
    Actually, i didn't rename it.. I allowed the user to enter the file name the file is generated as
    name += ".doc";
    fstream file (name.c_str());
    
    and instead of renaming the main file, I copied the contents of main file in to the generated file.. This seems much better than renaming it..