本文整理汇总了C++中std::ostream::put方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::put方法的具体用法?C++ ostream::put怎么用?C++ ostream::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostream
的用法示例。
在下文中一共展示了ostream::put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_output_seekable
bool test_output_seekable(std::ostream& io)
{
int i; // old 'for' scope workaround.
// Test seeking with ios::cur
for (i = 0; i < data_reps; ++i) {
for (int j = 0; j < chunk_size; ++j)
io.put(narrow_data()[j]);
io.seekp(-chunk_size, BOOST_IOS::cur);
io.write(narrow_data(), chunk_size);
}
// Test seeking with ios::beg
std::streamoff off = 0;
io.seekp(0, BOOST_IOS::beg);
for (i = 0; i < data_reps; ++i, off += chunk_size) {
for (int j = 0; j < chunk_size; ++j)
io.put(narrow_data()[j]);
io.seekp(off, BOOST_IOS::beg);
io.write(narrow_data(), chunk_size);
}
// Test seeking with ios::end
io.seekp(0, BOOST_IOS::end);
off = io.tellp();
io.seekp(-off, BOOST_IOS::end);
for (i = 0; i < data_reps; ++i, off -= chunk_size) {
for (int j = 0; j < chunk_size; ++j)
io.put(narrow_data()[j]);
io.seekp(-off, BOOST_IOS::end);
io.write(narrow_data(), chunk_size);
}
return true;
}
示例2: join_lines_remove_shell_comments_function
void join_lines_remove_shell_comments_function(std::istream& is, std::ostream& os) {
bool skip = false;
char current;
while (is.get(current)) {
if (skip) {
if (current != '\n' && current != '\\')
continue;
}
else if (skip = (current == '#')) {
continue;
}
if (current != '\\') {
if (current == '\n')
skip = false;
if (!skip)
os.put(current);
continue;
}
if (!is.get(current)) {
if (!skip)
os.put('\\');
return;
}
if (skip || current == '\n')
continue;
os.put('\\');
os.put(current);
}
}
示例3: if
inline size_t
writeVarNumber(std::ostream& os, uint64_t varNumber)
{
if (varNumber < 253) {
os.put(static_cast<char>(varNumber));
return 1;
}
else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
os.put(static_cast<char>(253));
uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
os.write(reinterpret_cast<const char*>(&value), 2);
return 3;
}
else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
os.put(static_cast<char>(254));
uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
os.write(reinterpret_cast<const char*>(&value), 4);
return 5;
}
else {
os.put(static_cast<char>(255));
uint64_t value = htobe64(varNumber);
os.write(reinterpret_cast<const char*>(&value), 8);
return 9;
}
}
示例4: write_and_pad_shader_source_header
inline
void write_and_pad_shader_source_header(
std::ostream& output,
shader_source_header& header,
span_size_t source_text_size,
span_size_t& spos
)
{
using eagine::memory::is_aligned_as;
while(!is_aligned_as<shader_source_header>(spos)) {
output.put('\0');
++spos;
}
// if changing this also change shader_block
// in write_and_pad_program_source_header
const span_size_t size = 48;
span_size_t done = 0;
assert(size >= span_size(sizeof(shader_source_header)));
eagine::memory::const_address hdraddr(&header);
header.source_text.reset(hdraddr+std::ptrdiff_t(size),source_text_size);
output.write(static_cast<const char*>(hdraddr), sizeof(header));
spos += sizeof(header);
done += sizeof(header);
while(done < size)
{
output.put('\0');
++spos;
++done;
}
}
示例5: writePPM
void Image::writePPM(std::ostream& s) const {
s << "P6\n" << _width << " " << _height << "\n255\n";
unsigned int i;
double gamma = 1.0 / 2.2;
for (int y = 0; y < _height; y++) {
for (int x = 0; x < _width; x++) {
_pixels(y, x) = Color(
pow(_pixels(y, x)[0], gamma),
pow(_pixels(y, x)[1], gamma),
pow(_pixels(y, x)[2], gamma)
);
i = 256.0 * _pixels(y, x)[0];
if (i > 255)
i = 255;
s.put((unsigned char) i);
i = 256.0 * _pixels(y, x)[1];
if (i > 255)
i = 255;
s.put((unsigned char) i);
i = 256.0 * _pixels(y, x)[2];
if (i > 255)
i = 255;
s.put((unsigned char) i);
}
}
}
示例6: Write
FIT_UINT8 FieldDefinition::Write(std::ostream &file) const
{
file.put(num);
file.put(size);
file.put(type);
return 3;
}
示例7: 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;
}
}
示例8: Write
int Mesg::Write(std::ostream& file, const MesgDefinition* mesgDef) const
{
MesgDefinition mesgDefOnNull;
FIT_UINT8 mesgSize = 1;
file.put((localNum & FIT_HDR_TYPE_MASK)); // Message record header with local message number.
if (mesgDef == FIT_NULL)
{
mesgDefOnNull = MesgDefinition(*this);
mesgDef = &mesgDefOnNull;
}
for (FIT_UINT16 fieldDefIndex = 0; fieldDefIndex < (mesgDef->GetFields().size()); fieldDefIndex++)
{
const Field* field = GetField(mesgDef->GetFieldByIndex(fieldDefIndex)->GetNum());
FIT_UINT8 fieldSize = 0;
if (field != FIT_NULL)
{
fieldSize = field->Write(file);
if (fieldSize == 0)
return 0;
}
if (fieldSize < (mesgDef->GetFieldByIndex(fieldDefIndex)->GetSize()))
{
FIT_UINT8 baseTypeNum = ((mesgDef->GetFieldByIndex(fieldDefIndex)->GetType()) & FIT_BASE_TYPE_NUM_MASK);
if (baseTypeNum < FIT_BASE_TYPES)
{
FIT_UINT8 baseTypeByteIndex = (fieldSize % (baseTypeSizes[baseTypeNum]));
FIT_UINT8 numBytesRemaining = (mesgDef->GetFieldByIndex(fieldDefIndex)->GetSize()) - fieldSize;
while (numBytesRemaining--)
{
file.put(*(baseTypeInvalids[baseTypeNum] + baseTypeByteIndex));
if ((++baseTypeByteIndex) >= baseTypeSizes[baseTypeNum])
baseTypeByteIndex = 0;
fieldSize++;
}
}
else
{
return 0; // Do not continue if base type not supported.
}
}
mesgSize += fieldSize;
}
return mesgSize;
}
示例9: WriteToken
void InfixPrinter::WriteToken(std::ostream& aOutput, const std::string& aString)
{
if (IsAlNum(iPrevLastChar) && (IsAlNum(aString[0]) || aString[0] == '_'))
aOutput.put(' ');
else if (IsSymbolic(iPrevLastChar) && IsSymbolic(aString[0]))
aOutput.put(' ');
aOutput.write(aString.c_str(), aString.size());
RememberLastChar(aString.back());
}
示例10:
size_t u8_wc_toutf8(std::ostream &out, long ch) {
if (ch < 0x80) {
out.put((char)ch);
return 1;
}
if (ch < 0x800) {
out.put((ch>>6) | 0xC0);
out.put((ch & 0x3F) | 0x80);
return 2;
}
示例11: writeSwappedOrder
void DoubleWord::writeSwappedOrder(std::ostream& destinationStream) const
{
DoubleWordValue value;
value.doubleWord = mValue;
destinationStream.put(value.bytes[3]);
destinationStream.put(value.bytes[2]);
destinationStream.put(value.bytes[1]);
destinationStream.put(value.bytes[0]);
}
示例12: writeEscaped
void writeEscaped(std::ostream &out, InputIterator begin, InputIterator end, char delim = ',')
{
for (; begin != end; ++begin)
{
char c = *begin;
if (c == delim || c == '\\')
out.put('\\');
out.put(c);
}
}
示例13: operator
void operator () (std::ostream &file,
const film< rgb<uint8_t>, E > &image) {
typedef typename film< rgb<uint8_t>, E >::size_type size_type;
for ( size_type r = 0; r < image.height(); ++r )
for ( size_type c = 0; c < image.width(); ++c ) {
rgb<uint8_t> col(image[c][r]);
file.put(col.blue());
file.put(col.green());
file.put(col.red());
}
}
示例14: encodeSkipName
void LafsFlat::encodeSkipName(std::ostream& out, const int iNext)
{
out.put('.');
out.put(0);
WORD wBuffer = iNext;
out.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD));
out.put(0);
out.put(0);
}
示例15: SaveInt
//
// SaveInt
//
static void SaveInt(std::ostream &save, biguint i)
{
if(!i) return;
SaveInt(save, i / 16);
save.put("0123456789ABCDEF"[i % 16]);
}