CrazyEngineers
  • 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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberNov 7, 2012

    What language you are using?
    Generate file using <Student_id>_<FileName>.
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberNov 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++
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberNov 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.😁
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberNov 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!!
    Are you sure? This action cannot be undone.
    Cancel
  • grsalvi

    MemberNov 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.
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberNov 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!!
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberNov 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?
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberNov 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..
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register