本文整理汇总了C++中std::istream::exceptions方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::exceptions方法的具体用法?C++ istream::exceptions怎么用?C++ istream::exceptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::exceptions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
[[nodiscard]]
inline size_t read(std::istream& Stream, const range<char*>& Buffer)
{
{
const auto Exceptions = Stream.exceptions();
Stream.exceptions(Exceptions & ~(Stream.failbit | Stream.eofbit));
SCOPE_EXIT{ Stream.exceptions(Exceptions); };
Stream.read(Buffer.data(), Buffer.size());
if (!Stream.bad() && Stream.eof())
Stream.clear();
}
return Stream.gcount();
}
示例2: load
//Load a unit from the input stream
Unit Unit::load(std::istream& in)
{
in.exceptions(std::istream::failbit | std::istream::eofbit);
std::vector<int> levels(7);
std::string iacode;
std::for_each(levels.begin(), levels.end(), [&in](int& level) {
in >> level;
});
示例3: MaximizationStep
EMAlg::EMAlg( const Evidence &evidence, InfAlg &estep, std::istream &msteps_file )
: _evidence(evidence), _estep(estep), _msteps(), _iters(0), _lastLogZ(), _max_iters(MAX_ITERS_DEFAULT), _log_z_tol(LOG_Z_TOL_DEFAULT)
{
msteps_file.exceptions( std::istream::eofbit | std::istream::failbit | std::istream::badbit );
size_t num_msteps = -1;
msteps_file >> num_msteps;
_msteps.reserve(num_msteps);
for( size_t i = 0; i < num_msteps; ++i )
_msteps.push_back( MaximizationStep( msteps_file, estep.fg() ) );
}
示例4: setBody
Error setBody(std::istream& is,
const Filter& filter,
std::streamsize buffSize = 128)
{
try
{
// set exception mask (required for proper reporting of errors)
is.exceptions(std::istream::failbit | std::istream::badbit);
// setup filtering stream for writing body
boost::iostreams::filtering_ostream filteringStream ;
// don't bother adding the filter if it is the NullOutputFilter
if ( !boost::is_same<Filter, NullOutputFilter>::value )
filteringStream.push(filter, buffSize);
// handle gzip
if (contentEncoding() == kGzipEncoding)
#ifdef _WIN32
// never gzip on win32
removeHeader("Content-Encoding");
#else
// add gzip compressor on posix
filteringStream.push(boost::iostreams::gzip_compressor(), buffSize);
#endif
// buffer to write to
std::ostringstream bodyStream;
filteringStream.push(bodyStream, buffSize);
// copy input stream
boost::iostreams::copy(is, filteringStream, buffSize);
// set body
body_ = bodyStream.str();
setContentLength(body_.length());
// return success
return Success();
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
return error;
}
}
示例5: LoadFromStream
void RoomList::LoadFromStream(std::istream &in)
{
std::string ris;
std::getline(in, ris);
if (ris != "SERVER LIST") throw Net::NetExn("Invalid format: Missing preamble");
in.exceptions(std::istream::badbit | std::istream::failbit);
bool foundScoreServer = false;
for (;;) {
int type;
try {
in >> type;
}
catch (std::istream::failure&) {
// End of stream.
break;
}
try {
switch (type) {
case 0: // Score server
in >> scoreServer;
foundScoreServer = true;
break;
case 1: // Room entry
rooms.push_back(new Server());
in >> *(rooms.back());
break;
case 2: // Room w/ ladder server.
// Currently unused.
break;
case 8: // Public banner
banners.push_back(new Banner());
in >> *(banners.back());
break;
case 9: // Registered banner
// Currently ignored.
break;
}
// Consume trailing characters in line.
std::getline(in, ris);
}
catch (std::istream::failure&) {
throw Net::NetExn("Parse error");
}
}
// Verify data.
if (!foundScoreServer) {
throw Net::NetExn("No score server");
}
if (rooms.empty()) {
throw Net::NetExn("No rooms available");
}
if (!banners.empty()) {
curBanner = banners.front();
curBannerIdx = 0;
}
}