当前位置: 首页>>代码示例>>C++>>正文


C++ ostream::put方法代码示例

本文整理汇总了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;
}
开发者ID:AsherBond,项目名称:PDAL,代码行数:34,代码来源:verification.hpp

示例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);
	}
}
开发者ID:tbfe-de,项目名称:mc-cpp11-BLWS,代码行数:29,代码来源:join_lines.cpp

示例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;
  }
}
开发者ID:cesarghali,项目名称:ndn-cxx-PITless,代码行数:26,代码来源:tlv.hpp

示例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;
	}
}
开发者ID:matus-chochlik,项目名称:oglplu2,代码行数:35,代码来源:program_file_io.hpp

示例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);
        }
    }
}
开发者ID:vmichele,项目名称:RAY_TRACER,代码行数:30,代码来源:Image.cpp

示例6: Write

FIT_UINT8 FieldDefinition::Write(std::ostream &file) const
{
   file.put(num);
   file.put(size);
   file.put(type);

   return 3;
}
开发者ID:dgaff,项目名称:fitsdk,代码行数:8,代码来源:fit_field_definition.cpp

示例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;
    }
}
开发者ID:Albermg7,项目名称:boost,代码行数:57,代码来源:ios_state_test.cpp

示例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;
}
开发者ID:StefanHubner,项目名称:fit,代码行数:56,代码来源:fit_mesg.cpp

示例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());
}
开发者ID:RicardoDeLosSantos,项目名称:yacas,代码行数:10,代码来源:infixparser.cpp

示例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;
  }
开发者ID:tristan,项目名称:cclojure,代码行数:10,代码来源:utf8.cpp

示例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]);
	}
开发者ID:aserkan,项目名称:cPlusPlus,代码行数:10,代码来源:DoubleWord.cpp

示例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);
        }
    }
开发者ID:chilabot,项目名称:chila,代码行数:11,代码来源:dsv.hpp

示例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());
         }
 }
开发者ID:EEmmanuel7,项目名称:AnimRay,代码行数:11,代码来源:targa.hpp

示例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);
}
开发者ID:JeremyWildsmith,项目名称:DCPUOS,代码行数:12,代码来源:LafsFlat.cpp

示例15: SaveInt

//
// SaveInt
//
static void SaveInt(std::ostream &save, biguint i)
{
   if(!i) return;

   SaveInt(save, i / 16);
   save.put("0123456789ABCDEF"[i % 16]);
}
开发者ID:DavidPH,项目名称:DH-acc,代码行数:10,代码来源:ObjectArchive.cpp


注:本文中的std::ostream::put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。