1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-30 19:03:12 +00:00
codecrypt/src/iohelpers.cpp

39 lines
1.2 KiB
C++
Raw Normal View History

2013-04-20 07:49:20 +00:00
/*
* This file is part of Codecrypt.
*
* Codecrypt is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Codecrypt is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Codecrypt. If not, see <http://www.gnu.org/licenses/>.
*/
2013-04-20 21:08:09 +00:00
#include "iohelpers.h"
2013-04-20 07:49:20 +00:00
2013-04-20 21:08:09 +00:00
bool redirect_cin (const std::string& fn)
{
static std::ifstream alt_cin;
alt_cin.open (fn.c_str(), std::ios::in | std::ios::binary);
if (alt_cin.fail() ) return false;
std::cin.rdbuf (alt_cin.rdbuf() );
return true;
}
2013-04-20 07:49:20 +00:00
2013-04-20 21:08:09 +00:00
bool redirect_cout (const std::string& fn)
{
2013-04-21 11:13:10 +00:00
static std::ofstream alt_cout;
2013-04-20 21:08:09 +00:00
alt_cout.open (fn.c_str(), std::ios::out | std::ios::binary);
if (alt_cout.fail() ) return false;
std::cout.rdbuf (alt_cout.rdbuf() );
return true;
}
2013-04-21 12:22:21 +00:00