1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[C++] Dynamic File Naming

  1. Sep 20, 2012 #1

    I'm wondering how to name/open a file whose name is given by a string with an integer appended at the end, i.e., something in the style of the following. Thank you!

    int i = 5;

    ofstream fout;

    string s = "Hello " + i;


    // write something to the file

  2. jcsd
  3. Sep 20, 2012 #2


    User Avatar

    Staff: Mentor

    I would take

    Code (Text):
    char filename[32];


    route, but I am not convinced it is how it should be done in C++. I started with C and have tendency to code in C+.
  4. Sep 20, 2012 #3
    Thank you. Worked perfectly.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Dynamic File Naming Date
Paint and Vertical Flow Wednesday at 6:29 PM
Fluid Mechanics air velocity Jan 7, 2018
Read specific lines from a file using fortran90 Dec 18, 2017
Finding the density inside a tank as air escapes Dec 12, 2017