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; }
Explanation / Answer
please rate - thanks I don't totally understand the question. but this will create 3files myFile1.txt 2 and 3 #include #include using namespace std; int main() { char buffer [50]={"myFilex.txt"}; ofstream out; for (char i='1';iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.