本文整理汇总了C++中ostream::rdbuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::rdbuf方法的具体用法?C++ ostream::rdbuf怎么用?C++ ostream::rdbuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::rdbuf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: out
Logger::Logger(ostream &out) : out(out.rdbuf())
{
pthread_mutex_lock(&counterLock);
threadCount++;
pthread_mutex_unlock(&counterLock);
clientPort = 0;
if(threadCount==1)
{
if(pthread_attr_init(&threadAttr))
{
out<<"ERROR: Failed to initialize thread attribute"<<endl;
return;
}
if(pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_JOINABLE))
{
out<<"ERROR: Failed to set detach state"<<endl;
out<<"ERROR: Failed to allocate memory for LoggerImpl"<<endl;
return;
}
//First ever Logger instance gets to start the log writing thread
int ret = pthread_create(&thread, &threadAttr, logWriter, this);
if(ret)
{
out<<"ERROR: Failed to start log printer thread. Error code: "<<strerror(ret)<<endl;
threadCount = 0;
return;
}
}
}
示例2: min
ostream& __STL_CALL operator<<(ostream& __os,
const basic_string<_CharT,_Traits,_Alloc>& __s)
{
__STL_USING_VENDOR_STD
streambuf* __buf = __os.rdbuf();
if (__buf) {
size_t __n = __s.size();
size_t __pad_len = 0;
const bool __left = (__os.flags() & ios::left) !=0;
const size_t __w = __os.width();
if (__w > 0) {
__n = min(__w, __n);
__pad_len = __w - __n;
}
if (!__left)
__sgi_string_fill(__os, __buf, __pad_len);
const size_t __nwritten = __buf->sputn(__s.data(), __n);
if (__left)
__sgi_string_fill(__os, __buf, __pad_len);
if (__nwritten != __n)
__os.clear(__os.rdstate() | ios::failbit);
__os.width(0);
}
else
__os.clear(__os.rdstate() | ios::badbit);
return __os;
}
示例3: redirect
void redirect (ostream& strm)
{
ofstream file("redirect.txt");
// save output buffer of the stream
streambuf* strm_buffer = strm.rdbuf();
// redirect ouput into the file
strm.rdbuf (file.rdbuf());
file << "one row for the file" << endl;
strm << "one row for the stream" << endl;
// restore old output buffer
strm.rdbuf (strm_buffer);
} // closes file AND its buffer automatically
示例4: redirect
void redirect (ostream& strm)
{
// save output buffer of the stream
// - use unique pointer with deleter that ensures to restore
// the original output buffer at the end of the function
auto del = [&](streambuf* p) {
strm.rdbuf(p);
};
unique_ptr<streambuf,decltype(del)> origBuffer(strm.rdbuf(),del);
// redirect ouput into the file redirect.txt
ofstream file("redirect.txt");
strm.rdbuf (file.rdbuf());
file << "one row for the file" << endl;
strm << "one row for the stream" << endl;
} // closes file AND its buffer automatically
示例5: ostream
SVOutStream::SVOutStream(ostream& out, const String& sep,
const String& replacement,
String::QuotingMethod quoting) :
ostream(out.rdbuf()), sep_(sep), replacement_(replacement), nan_("nan"),
inf_("inf"), quoting_(quoting), modify_strings_(true), newline_(true)
{
// use high decimal precision (appropriate for double):
precision(std::numeric_limits<double>::digits10);
}
示例6:
bool
ios_base::sync_with_stdio(bool sync)
{
static ios_base::Init __make_sure_streams_are_constructed;
static bool previous_sync = true;
bool result = previous_sync;
previous_sync = sync;
cin.rdbuf()->pubsetbuf(0, !sync);
cout.rdbuf()->pubsetbuf(0, !sync);
clog.rdbuf()->pubsetbuf(0, !sync);
cerr.rdbuf()->pubsetbuf(0, !sync);
#ifndef _EWL_NO_WCHART_CPP_SUPPORT
wcin.rdbuf()->pubsetbuf(0, !sync);
wcout.rdbuf()->pubsetbuf(0, !sync);
wclog.rdbuf()->pubsetbuf(0, !sync);
wcerr.rdbuf()->pubsetbuf(0, !sync);
#endif // _EWL_NO_WCHART_CPP_SUPPORT
return result;
}
示例7: genLineDirective
void genLineDirective( ostream &out )
{
std::streambuf *sbuf = out.rdbuf();
output_filter *filter = static_cast<output_filter*>(sbuf);
lineDirective( out, filter->fileName, filter->line + 1 );
}
示例8:
ostream::ostream(ostream const& rhs)
: std::ios(0), base_type(rhs.rdbuf()), impl_(rhs.impl_)
{
this->copyfmt(rhs);
this->clear(rhs.rdstate());
}
示例9: print_stream
// Threadsafe print a given stream.
void print_stream(ostream &strng)
{
cout << strng.rdbuf();
cout.flush();
strng.clear();
}
示例10: CheckInit
void
Redirect( ostream& from, ostream& to )
{
CheckInit();
from.rdbuf( to.rdbuf() );
}
示例11:
StreamBuf_Swapper(ostream & orig, ostream & replacement)
: buf_(orig.rdbuf()), str_(orig)
{
orig.rdbuf(replacement.rdbuf());
}
示例12:
void
Nav2Logging::deleteHandlers(ostream& logStream)
{
if (dynamic_cast<LogBuffer*>(logStream.rdbuf()) != NULL)
static_cast<LogBuffer*>(logStream.rdbuf())->deleteHandlers();
}