本文整理汇总了C++中std::ostream::rdstate方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::rdstate方法的具体用法?C++ ostream::rdstate怎么用?C++ ostream::rdstate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostream
的用法示例。
在下文中一共展示了ostream::rdstate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
void set(std::istream& in, std::ostream& out, std::ostream& err) {
if (not activated) {
using namespace std;
in_buf = cin.rdbuf(); out_buf = cout.rdbuf(); err_buf = cerr.rdbuf();
in_state = cin.rdstate(); out_state = cin.rdstate(); err_state = cerr.rdstate();
cin.rdbuf(in.rdbuf()); cout.rdbuf(out.rdbuf()); cerr.rdbuf(err.rdbuf());
cin.exceptions(ios_base::goodbit); cout.exceptions(ios_base::goodbit); cerr.exceptions(ios_base::goodbit);
cin.clear(in.rdstate()); cout.clear(out.rdstate()); cerr.clear(err.rdstate());
}
}
示例2: its
// Save & change and restore stream properties
void
saver_tests_2
(
std::istream & input,
std::ostream & output,
std::ostream & err
)
{
using std::locale;
using std::ios_base;
boost::io::ios_tie_saver const its( input, &err );
boost::io::ios_rdbuf_saver const irs( output, err.rdbuf() );
boost::io::ios_iword_saver const iis( output, my_index, 69L );
boost::io::ios_pword_saver const ipws( output, my_index, &err );
output << "The data is (a third time; adding the numbers):\n";
boost::io::ios_flags_saver const ifls( output, (output.flags()
& ~ios_base::adjustfield) | ios_base::showpos | ios_base::boolalpha
| (ios_base::internal & ios_base::adjustfield) );
boost::io::ios_precision_saver const iprs( output, 9 );
boost::io::ios_fill_saver const ifis( output, '@' );
output << '\t' << test_string << '\n';
boost::io::ios_width_saver const iws( output, 12 );
output.put( '\t' );
output << test_num1 + test_num2;
output.put( '\n' );
locale loc( locale::classic(),
new backward_bool_names );
boost::io::ios_locale_saver const ils( output, loc );
output << '\t' << test_bool << '\n';
BOOST_CHECK( &err == output.pword(my_index) );
BOOST_CHECK( 69L == output.iword(my_index) );
try
{
boost::io::ios_exception_saver const ies( output, ios_base::eofbit );
boost::io::ios_iostate_saver const iis( output, output.rdstate()
| ios_base::eofbit );
BOOST_ERROR( "previous line should have thrown" );
}
catch ( ios_base::failure &f )
{
err << "Got the expected I/O failure: \"" << f.what() << "\".\n";
BOOST_CHECK( output.exceptions() == ios_base::goodbit );
}
catch ( ... )
{
err << "Got an unknown error when doing exception test!\n";
throw;
}
}
示例3: WriteHeader
void AppLogChannel::WriteHeader(std::ostream &os)
{
StartTrace(AppLogChannel.WriteHeader);
ROAnything header = GetChannelInfo()["Header"];
Trace("os state before writing header: " << (long)os.rdstate());
long szh = header.GetSize();
for (long i = 0; i < szh; ++i) {
os << header[i].AsCharPtr("");
if (!os) {
SYSERROR("Write Header to logfile failed");
return;
}
}
if ( szh > 0 ) {
os << std::endl;
}
Trace("os state " << (long)os.rdstate());
}