Commit e465b555 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] function to load a file into a string

parent 27d38fcd
......@@ -23,3 +23,21 @@
//---------------------------------------------------------------------------
#include "WIOTools.h"
#include "exceptions/WFileNotFound.h"
std::string wiotools::getStringFromFile( const std::string& filename )
{
std::ifstream input( filename.c_str() );
if ( !input.is_open() )
{
throw WFileNotFound( std::string( "The file \"" ) + filename +
std::string( "\" does not exist." ) );
}
std::string buf;
std::string line;
while( std::getline( input, line ) )
{
buf += line;
}
return buf;
}
......@@ -34,6 +34,8 @@
#include <boost/filesystem.hpp>
#include "WExportCommon.h"
/**
* Namespaces for several tools we may need while doing IO
*/
......@@ -124,5 +126,13 @@ namespace wiotools
// 3. file names like "/tmp/pansen" or "C:\pansen" are platform dependent
return std::string( std::tmpnam( NULL ) );
}
/**
* Get the contens of a file as a string.
* \param filename
* \return the file content in as string.
*/
std::string OWCOMMON_EXPORT getStringFromFile( const std::string& filename );
} // end of namespace
#endif // WIOTOOLS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment