Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

### liv1n9's blog

By liv1n9, history, 9 months ago, ,

Hi!

I'm writing a C++ program to generate testcases. It has a class Task which contains:

fstream in, out;


and contructor

Task(string fileIn, string fileOut) {
this->fileIn = fileIn;
this->fileOut = fileOut;
in.open(fileIn.c_str(), ios::in);
out.open(fileOut.c_str(), ios::out);
}


This class will read input from file fileIn (which was generated), solve problem, then write output to file fileOut. No error so far, but the problem is that the program can just read and write with file, while i'm also wanting to do it with standard input/output stream, so that i can also use the program to submit. All i can do now is using a variable bool isFile and if/else statements, which mean i would have to write the input/output parts twice. I'm thinking about a way which i can change from file stream to standard stream directly but i don't know if it were possible.

 » 9 months ago, # |   +8 replace fstream with istream/ostream and do in.rdbuf(cin.rdbuf()); — in will be reading from standart input. Read http://en.cppreference.com or http://www.cplusplus.com/ if you want to do something with STL.