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


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

本文整理汇总了C++中std::ostream::bad方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::bad方法的具体用法?C++ ostream::bad怎么用?C++ ostream::bad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ostream的用法示例。


在下文中一共展示了ostream::bad方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: write_header

 bool client_request::write_header(std::ostream &os) {
     std::string ka;
     if (keep_alive) {
         ka="keep-alive";
     } else {
         ka="close";
     }
     auto i=headers.find("connection");
     if (i==headers.end()) {
         headers.insert(std::make_pair("Connection", ka));
     } else {
         i->second.assign(ka);
     }
     if (!common::request::write_header(os)) return false;
     return !os.eof() && !os.fail() && !os.bad();
 }
开发者ID:asianhawk,项目名称:fibio,代码行数:16,代码来源:client.cpp

示例2: docopy_noseek

static int docopy_noseek(std::istream &i, std::ostream &o)
{
	char	buf[BUFSIZ];

	i.read(buf, sizeof(buf));

	int	x;

	while ((x=i.gcount()) > 0)
	{
		o.write(buf, x);
		i.read(buf, sizeof(buf));
	}
	if (o.bad() || i.bad())
		return (EX_OSERR);
	return (0);
}
开发者ID:MhdAlyan,项目名称:courier,代码行数:17,代码来源:cmlmmoderate.C

示例3: write

 bool client_request::write(std::ostream &os) {
     // Set "content-length"
     auto i=headers.find("content-length");
     if (i==headers.end()) {
         headers.insert(std::make_pair("Content-Length", boost::lexical_cast<std::string>(get_content_length())));
     } else {
         i->second.assign(boost::lexical_cast<std::string>(get_content_length()));
     }
     // Write header
     if (!write_header(os)) return false;
     // Write body
     if (!raw_body_stream_.vector().empty()) {
         os.write(&(raw_body_stream_.vector()[0]), raw_body_stream_.vector().size());
     }
     os.flush();
     return !os.eof() && !os.fail() && !os.bad();
 }
开发者ID:asianhawk,项目名称:fibio,代码行数:17,代码来源:client.cpp

示例4: save

easyqrpng_error_t easyqrpng::save(std::ostream &output)
{
	if (_impl->qrcode == NULL)
		return setError(EASYQRPNGERR_NOT_ENCODED);

	int width = _impl->qrcode->width;
	int margin = _impl->margin;
	int size = _impl->targetWidth / width;
	if (size < 1)
		size = 1;

	const unsigned char colWhite[] = { 255, 255, 255 };
	const unsigned char colBlack[] = { 0, 0, 0 };
	
	CImg<unsigned char> cimage(width*size + margin*2, width*size + margin*2, 1, 3);
	cimage.draw_rectangle(0, 0, cimage.width(), cimage.height(), colWhite);

	unsigned char *p = _impl->qrcode->data;
	for(int y=0; y<width; y++) {
		for(int x=0; x<width; x++) {
			const unsigned char *cl = (*p&1) ? &colBlack[0] : &colWhite[0];
			cimage.draw_rectangle(margin + x*size, margin + y*size, margin + x*size+size, margin + y*size+size, cl);
			p++;
		}
	}

	// must convert to lodepng format
	CImg<unsigned char> cimageinter = cimage.get_permute_axes("cxyz");

	unsigned char* out;
	size_t outsize;
	unsigned error = lodepng_encode24(&out, &outsize, cimageinter.data(), cimage.width(), cimage.height());
	if (error)
		return setError(EASYQRPNGERR_ENCODEPNG_ERROR);

	output.write(reinterpret_cast<const char*>(out), outsize);
	if (output.bad())
		return setError(EASYQRPNGERR_ENCODEPNG_ERROR);

	return setError(EASYQRPNGERR_OK);
}
开发者ID:RangelReale,项目名称:easyqrpng,代码行数:41,代码来源:easyqrpngpp.cpp

示例5: Write

void MeshKernel::Write (std::ostream &rclOut) const 
{
    if (!rclOut || rclOut.bad())
        return;

    Base::OutputStream str(rclOut);

    // Write a header with a "magic number" and a version
    str << (uint32_t)0xA0B0C0D0;
    str << (uint32_t)0x010000;

    char szInfo[257]; // needs an additional byte for zero-termination
    strcpy(szInfo, "MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-"
                   "MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-"
                   "MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-"
                   "MESH-MESH-MESH-\n");
    rclOut.write(szInfo, 256);

    // write the number of points and facets
    str << (uint32_t)CountPoints() << (uint32_t)CountFacets();

    // write the data
    for (MeshPointArray::_TConstIterator it = _aclPointArray.begin(); it != _aclPointArray.end(); ++it) {
        str << it->x << it->y << it->z;
    }

    for (MeshFacetArray::_TConstIterator it = _aclFacetArray.begin(); it != _aclFacetArray.end(); ++it) {
        str << (uint32_t)it->_aulPoints[0] 
            << (uint32_t)it->_aulPoints[1] 
            << (uint32_t)it->_aulPoints[2];
        str << (uint32_t)it->_aulNeighbours[0] 
            << (uint32_t)it->_aulNeighbours[1] 
            << (uint32_t)it->_aulNeighbours[2];
    }

    str << _clBoundBox.MinX << _clBoundBox.MaxX;
    str << _clBoundBox.MinY << _clBoundBox.MaxY;
    str << _clBoundBox.MinZ << _clBoundBox.MaxZ;
}
开发者ID:DeepSOIC,项目名称:FreeCAD-ellipse,代码行数:39,代码来源:MeshKernel.cpp

示例6: write

void PropertyReader::write(std::ostream& os, const std::string& message, const Properties& props) const
{
  Properties::const_iterator it = props.begin(), end = props.end();
  
  std::istringstream lineStream(message);
  std::string line;

  // print the comments taking in account the end of lines
  while (std::getline(lineStream, line))
  {
    os << "#" << line << "\n";
  }

  for (; it != end; ++it)
  {    
    // Write property on the stream
    os << it->first << "=" << it->second << "\n";
  }

  if (os.bad())
    throw PropertyStreamError();
}
开发者ID:Separius,项目名称:TripleA-3DSoccerSimulation,代码行数:22,代码来源:PropertyReader.cpp

示例7: rebuild_pe

//Rebuild PE image and write it to "out" ostream
//If strip_dos_header is true, DOS headers partially will be used for PE headers
//If change_size_of_headers == true, SizeOfHeaders will be recalculated automatically
//If save_bound_import == true, existing bound import directory will be saved correctly (because some compilers and bind.exe put it to PE headers)
void rebuild_pe(pe_base& pe, std::ostream& out, bool strip_dos_header, bool change_size_of_headers, bool save_bound_import)
{
    if(out.bad())
        throw pe_exception("Stream is bad", pe_exception::stream_is_bad);

    if(save_bound_import && pe.has_bound_import())
    {
        if(pe.section_data_length_from_rva(pe.get_directory_rva(image_directory_entry_bound_import), pe.get_directory_rva(image_directory_entry_bound_import), section_data_raw, true)
            < pe.get_directory_size(image_directory_entry_bound_import))
            throw pe_exception("Incorrect bound import directory", pe_exception::incorrect_bound_import_directory);
    }

    //Change ostream state
    out.exceptions(std::ios::goodbit);
    out.clear();
    
    uint32_t original_bound_import_rva = pe.has_bound_import() ? pe.get_directory_rva(image_directory_entry_bound_import) : 0;
    if(original_bound_import_rva && original_bound_import_rva > pe.get_size_of_headers())
    {
        //No need to do anything with bound import directory
        //if it is placed inside of any section, not headers
        original_bound_import_rva = 0;
        save_bound_import = false;
    }

    {
        image_dos_header dos_header;

        //Rebuild PE image headers
        rebuild_pe(pe, dos_header, strip_dos_header, change_size_of_headers, save_bound_import);

        //Write DOS header
        out.write(reinterpret_cast<const char*>(&dos_header), strip_dos_header ? 8 * sizeof(uint16_t) : sizeof(image_dos_header));
    }

    //If we have stub overlay, write it too
    {
        const std::string& stub = pe.get_stub_overlay();
        if(stub.size())
        {
            out.write(stub.data(), stub.size());
            size_t aligned_size = pe_utils::align_up(stub.size(), sizeof(uint32_t));
            //Align PE header, which is right after rich overlay
            while(aligned_size > stub.size())
            {
                out.put('\0');
                --aligned_size;
            }
        }
    }
    
    //Write NT headers
    out.write(static_cast<const pe_base&>(pe).get_nt_headers_ptr(), pe.get_sizeof_nt_header()
        - sizeof(image_data_directory) * (image_numberof_directory_entries - pe.get_number_of_rvas_and_sizes()));

    //Write section headers
    const section_list& sections = pe.get_image_sections();
    for(section_list::const_iterator it = sections.begin(); it != sections.end(); ++it)
    {
        out.write(reinterpret_cast<const char*>(&(*it).get_raw_header()), sizeof(image_section_header));
    }

    //Write bound import data if requested
    if(save_bound_import && pe.has_bound_import())
    {
        out.write(pe.section_data_from_rva(original_bound_import_rva, section_data_raw, true),
            pe.get_directory_size(image_directory_entry_bound_import));
    }

    //Write section data finally
    for(section_list::const_iterator it = sections.begin(); it != sections.end(); ++it)
    {
        const section& s = *it;

        std::streamoff wpos = out.tellp();

        //Fill unused overlay data between sections with null bytes
        for(unsigned int i = 0; i < s.get_pointer_to_raw_data() - wpos; i++)
            out.put(0);

        //Write raw section data
        out.write(s.get_raw_data().data(), s.get_size_of_raw_data());
    }
}
开发者ID:apriorit,项目名称:portable-executable-library,代码行数:88,代码来源:pe_rebuilder.cpp


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