open output file only if input file opens correctly. And it's not good idea call std::ostream::open() some times without close()