C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

20 years ago
/** @file
$Id$
$Date$
$Author$
@copy © Marc Wäckerlin
@license LGPL, see file <a href="license.html">COPYING</a>
$Log$
Revision 1.1 2005/01/07 00:31:38 marc
initial version
1 2 3 4 5 6 7 8
5678901234567890123456789012345678901234567890123456789012345678901234567890
*/
#ifndef __MRW_FILE_HPP__
#define __MRW_FILE_HPP__
#include <mrw/exception.hpp>
#include <string>
#include <fstream>
namespace mrw {
class File {
public:
static void copy(std::string from, std::string to) throw (std::exception) {
std::ifstream is(from.c_str());
if (!is)
throw mrw::invalid_argument("Cannot read file: '"+from+"'");
is.seekg(0, std::ios::end);
int size(is.tellg());
std::string contents(size, 0); // make buffer long enough to store all
is.seekg(0, std::ios::beg);
is.read(contents.begin().operator->(), size); // hack to get the buffer
if (!is.good() && is.eof())
throw mrw::invalid_argument("Cannot read file: '"+from+"'");
std::ofstream os(to.c_str());
os<<contents;
if (!os) throw mrw::invalid_argument("Cannot write file: '"+to+"'");
}
};
}
#endif