0

Why does this not work, and are there other alternatives?
This will eventually be used in a loop of sorts.. the different fileName's will be determined by the program in real time..

#include <fstream>
#include <iostream>

int main (int argc, char** argv)
{
    std::string fileName; 
    fileName = "testFile.txt"; // passed to program at runtime
    
    std::ofstream output;
    output.open(fileName); // path of ofstream = string fileName
    output << "success";
    output.close();
    
    return 0;
}

:?:

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

> Why does this not work,
...and next time describing the problem in detail along with error messages would be recommended rather than the so famous 'this does not work' statement.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.