input and output data file names

I have task in c++ to do but i dont understand what it wants.It says "the program output and input data files name can be embedded in the program source file or read from screen"

can anyone help me explain what it wants? and is there any examples to look at?
Well, to embed the name in the program means to do
1
2
fstream file;
file.open("foo.txt");

To read from screen means to do
1
2
3
4
char str[80];
fstream file;
cin.getline(str, 80);
file.open(str);

I guess, since there is an "or", it doesn't care..
so to read from the screen is like typing the file name on the output screen?
You can either prompt the user for the name and save it as a string or character array then use that saved variable to open the file, this should be done with a check to make sure the file they are entering exists and continue prompting them until the user enters a file that does in fact exist. This should be done while reading input, output it doesn't matter as a file should be created regardless.

Reading from the screen I would assumes means reading user input from a prompt asking for the file name.
Using std::strings with std::fstream for reference (Read filename in from screen AKA user input):
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <string>
#include <fstream>
#include <iostream>

int main ()
{
   std::string filename;
   std::ifstream inFile;
   std::getline (std::cin, filename);
   inFile.open(filename.c_str());
   if (!inFile.is_open())
      std::cout << "Bad file!\n";
}
Topic archived. No new replies allowed.