So the code below is supposed to create 3 text files. Eachwith the names myFile1
ID: 3616831 • Letter: S
Question
So the code below is supposed to create 3 text files. Eachwith the names myFile1, myFile2, and myFile3.those names are stores in the variable 'buffer' but the linethat creates the txt files doesn't work when i try to pass a variable into it instead of physicallytyping "stringname.txt"
HOw can i pass this variable into that function or maybeanother function that creates txt files?
#include <stdio.h> #include <stdlib.h> #include <fstream> using namespace std; int main () { char buffer [50]; for (int i=0;i<3;i++) { sprintf (buffer, "myFile%d.txt ", i); ofstream fileout; fileout.open(buffer); printf(buffer); } return 0; } So the code below is supposed to create 3 text files. Eachwith the names myFile1, myFile2, and myFile3.
those names are stores in the variable 'buffer' but the linethat creates the txt files doesn't work when i try to pass a variable into it instead of physicallytyping "stringname.txt"
HOw can i pass this variable into that function or maybeanother function that creates txt files?
#include <stdio.h> #include <stdlib.h> #include <fstream> using namespace std; int main () { char buffer [50]; for (int i=0;i<3;i++) { sprintf (buffer, "myFile%d.txt ", i); ofstream fileout; fileout.open(buffer); printf(buffer); } return 0; }