本文整理汇总了C++中std::ifstream::rdbuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ifstream::rdbuf方法的具体用法?C++ ifstream::rdbuf怎么用?C++ ifstream::rdbuf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ifstream
的用法示例。
在下文中一共展示了ifstream::rdbuf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Logger(string outFile)
{
fileName=outFile;
std::filebuf* buf = is.rdbuf();
buf->open(fileName.c_str(),std::ios_base::out|std::ios_base::app);
std::clog.rdbuf(buf);
}
示例2: redirect_cin
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;
}
示例3: appendSingleFile
bool FileTemplater::appendSingleFile(std::ofstream* outputFile, const std::ifstream& inputFile)
{
// read input file into a string
std::stringstream ss;
ss << inputFile.rdbuf();
std::string str = ss.str();
// output it to file
outputFile->write(str.c_str(), str.size());
return true;
}
示例4: readWholeFileStream
inline std::string readWholeFileStream(std::ifstream& fileStream) {
std::stringstream stringStream;
stringStream << fileStream.rdbuf();
fileStream.close();
return stringStream.str();
}
示例5: readFile
std::string readFile(std::ifstream& in) {
std::stringstream sstr;
sstr << in.rdbuf();
return sstr.str();
}
示例6: LoadFrom_ifstream
// This code reads up the file, discards the bookends, and saves only the gibberish itself.
bool OTASCIIArmor::LoadFrom_ifstream(std::ifstream & fin)
{
std::stringstream buffer;
buffer << fin.rdbuf();
std::string contents(buffer.str());
OTString theString;
theString.Set(contents.c_str());
return LoadFromString(theString);
}
示例7: cout
StdHandleSaver(const char* in, const char* out) :
cin(std::cin.rdbuf()), cout(std::cout.rdbuf()), cerr(std::cerr.rdbuf()), clog(std::clog.rdbuf()),
csh(in, out),
// NOTE: Using undocumented constructor accepting FILE*
// Only constructor accepts FILE* and swap is specified since C++11, so we need to use constructor
ifs(stdin), ofs(stdout)
{
std::cin.rdbuf(ifs.rdbuf());
std::cout.rdbuf(ofs.rdbuf());
std::cerr.rdbuf(ofs.rdbuf());
std::clog.rdbuf(ofs.rdbuf());
}
示例8: loadObstacle
VirtualRobot::ObstaclePtr ObjectIO::loadObstacle(const std::ifstream& xmlFile, const std::string& basePath /*= ""*/)
{
// load file
THROW_VR_EXCEPTION_IF(!xmlFile.is_open(), "Could not open XML file");
std::stringstream buffer;
buffer << xmlFile.rdbuf();
std::string objectXML(buffer.str());
VirtualRobot::ObstaclePtr res = createObstacleFromString(objectXML, basePath);
THROW_VR_EXCEPTION_IF(!res, "Error while parsing file.");
return res;
}
示例9: appendToAllFiles
bool FileTemplater::appendToAllFiles(std::vector<std::ofstream*> outputFiles, const std::ifstream& inputFile)
{
// read input file into a string
std::stringstream ss;
ss << inputFile.rdbuf();
std::string str = ss.str();
// output it to file
for (std::vector<std::ofstream*>::iterator it=outputFiles.begin(); it!=outputFiles.end(); ++it)
{
(*it)->write(str.c_str(), str.size());
}
return true;
}
示例10:
Newick::Newick(const std::ifstream& file_stream) {
if(file_stream) { // if file stream is open
std::stringstream buffer; // create a buffer
buffer << file_stream.rdbuf(); // and read into it
if ( check_newick_format(buffer.str()) ) { // if string looks fine
newick_string_m = buffer.str(); // copy the string
}
else {
std::cout << "Newick string has the wrong format!" << std::endl;
}
}
else {
std::cout << "Could not open the file!" << std::endl;
}
}
示例11: ReadRLE
void Targa::ReadRLE(std::ifstream &i)
{
assert(header.imageType == Header::RGBRLE); // For use loading run length encoded RGB files only
assert(pixelData.size() == 0);
unsigned bytesPerPixel = header.pixelSize/8;
pixelData.resize( header.width * header.height * 4 );
assert(i.good());
assert(i.is_open());
int x = 0;
int y = 0;
std::vector<char> restOfFile(std::istreambuf_iterator<char>(i.rdbuf()), std::istreambuf_iterator<char>());
for (std::vector<char>::const_iterator itt = restOfFile.begin(); itt != restOfFile.end(); )
//for(std::istreambuf_iterator<char> itt(i.rdbuf()); itt != std::istreambuf_iterator<char>();)
{
const bool runLengthPacket = (*itt & 0x80) != 0;
const int packetSize = 1 + (*itt & 0x7f);
++itt;
if (runLengthPacket)
{
// get the pixel, and paste packetSize into the data
const unsigned char b = *(itt++);
const unsigned char g = *(itt++);
const unsigned char r = *(itt++);
const unsigned char a = (bytesPerPixel == 4) ? *(itt++) : 255;
for (int p = 0; p < packetSize; ++p)
{
const int coord = x + y * 4;
pixelData[ 0 + coord ] = r;
pixelData[ 1 + coord ] = g;
pixelData[ 2 + coord ] = b;
pixelData[ 3 + coord ] = a;
if (++x == header.width)
{
++y;
x = 0;
}
}
}
else
{
for (int p = 0; p < packetSize; ++p)
{
const unsigned char b = *(itt++);
const unsigned char g = *(itt++);
const unsigned char r = *(itt++);
const unsigned char a = (bytesPerPixel == 4) ? *(itt++) : 255;
const int coord = x + y * 4;
pixelData[ 0 + coord ] = r;
pixelData[ 1 + coord ] = g;
pixelData[ 2 + coord ] = b;
pixelData[ 3 + coord ] = a;
if (++x == header.width)
{
++y;
x = 0;
}
}
}
}
}
示例12: stream
#include "vector_tile_util.hpp"
#include "vector_tile_projection.hpp"
#include "vector_tile_geometry_decoder.hpp"
#include "vector_tile_datasource.hpp"
#include "vector_tile_datasource_pbf.hpp"
#include "protozero/pbf_reader.hpp"
#include <boost/optional/optional_io.hpp>
#include <fstream>
TEST_CASE( "vector tile rasterize", "should try to decode windfail tile" ) {
// open vtile
std::ifstream stream("./test/data/0.0.0.vector.pbf",std::ios_base::in|std::ios_base::binary);
REQUIRE(stream.is_open());
std::string buffer(std::istreambuf_iterator<char>(stream.rdbuf()),(std::istreambuf_iterator<char>()));
REQUIRE(buffer.size() == 3812);
// uncompress gzip data
std::string uncompressed;
mapnik::vector_tile_impl::zlib_decompress(buffer,uncompressed);
REQUIRE(uncompressed.size() == 4934);
typedef vector_tile::Tile tile_type;
tile_type tile;
unsigned tile_size = 256;
mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
// first we render the raw tile directly to an image
{
mapnik::Map map(tile_size,tile_size,"+init=epsg:3857");
示例13:
/// Read the entire content of given file to string
inline const std::string read_file(std::ifstream& a_in) {
return static_cast<std::stringstream const&>(std::stringstream() << a_in.rdbuf()).str();
}
示例14:
g_property_file_parser::g_property_file_parser(std::ifstream& t) {
std::stringstream buffer;
buffer << t.rdbuf();
initialize(buffer.str());
}
示例15: read
void PGPCleartextSignature::read(std::ifstream & file){
std::stringstream s;
s << file.rdbuf();
std::string data = s.str();
read(data);
}