16 Write a program to read in a filename via stdin and write

[16] Write a program to read in a filename via stdin and write a C++ source template to it [8]. Ensure that the generated file compiles and runs [8]. Such a template would have at least a #include directive and an empty main function, ready to be filled. Once you have written this program, you may use it to jumpstart your work on other programs. Call your program source setup.cpp. must be c++ coding

Solution

#include <iostream.h>
#include <fstream.h>

void main() {
int i;
ofstream outfile(\"out.dat\",ios::out);

for (i=0;i<10;i++) {
outfile << i+1 << \"\ \";
}
}

C version:

#include <stdio.h>

void main() {
int i;
FILE *outfile;

outfile = fopen(\"out.dat\",\"w\");
for (i=0;i<10;i++) {
fprintf(outfile,\"%d\ \",i+1);
}
fclose(outfile);
}

[16] Write a program to read in a filename via stdin and write a C++ source template to it [8]. Ensure that the generated file compiles and runs [8]. Such a tem

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site