1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    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!

Homework Help: [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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook