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


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

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


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

示例1: RunTest

	void RunTest (std::string const & src, std::string const & password, std::ostream & out)
	{
		std::string cypher;
		{
			Crypt::Streamer streamer (password);
			streamer.SetInput (&src [0], src.size ());
			std::ostringstream out;
			streamer.Encrypt (out);
			cypher = out.str ();
		}
		std::string decoded;
		{
			Crypt::Streamer streamer (password);
			streamer.SetInput (&cypher [0], cypher.size ());
			std::ostringstream out;
			streamer.Decrypt (out);
			decoded = out.str ();
		}
		Assert (decoded.size () == src.size ());
		Assert (decoded == src);
	}
开发者ID:BartoszMilewski,项目名称:WinLib,代码行数:21,代码来源:Crypto.cpp

示例2: print_in_readelf_style

void print_in_readelf_style(std::ostream& s, const encap::frame_instrlist& instrs, Dwarf_Addr initial_loc)
{
	Dwarf_Addr loc = initial_loc;
	auto reg = [](int regnum) {
		std::ostringstream s;
		s << "r" << regnum << " (" << dwarf_regnames_for_elf_machine(elf_machine)[regnum]
					<< ")";
		return s.str();
	};
	
	for (auto i_instr = instrs.begin(); i_instr != instrs.end(); ++i_instr)
	{
		const char *opcode_name;
		int encoded_opcode = i_instr->fp_base_op << 6 | i_instr->fp_extended_op;
		int ret = lib::dwarf_get_CFA_name(encoded_opcode, &opcode_name);
		assert(ret == DW_DLV_OK);
		if (string(opcode_name) == "DW_CFA_extended") opcode_name = "DW_CFA_nop";
		s << "  " << opcode_name;
		
		switch (encoded_opcode)
		{
			// "packed" two-bit opcodes
			case DW_CFA_advance_loc: 
			case DW_CFA_advance_loc1:
			case DW_CFA_advance_loc2:
			case DW_CFA_advance_loc4:
				loc += i_instr->fp_offset_or_block_len;
				s << ": " << i_instr->fp_offset_or_block_len << " to " << setw(16) << setfill('0') << std::hex << loc << std::dec;
				break;
			case DW_CFA_offset:
				s << ": " << reg(i_instr->fp_register) 
					<< " at cfa" << std::showpos << (lib::Dwarf_Signed)(i_instr->fp_offset_or_block_len) << std::noshowpos;
				break;
			case DW_CFA_restore_extended: goto register_only;
			case DW_CFA_undefined: goto register_only;
			case DW_CFA_same_value: goto register_only;
			case DW_CFA_def_cfa_register: goto register_only;
			case DW_CFA_restore: goto register_only;
			register_only:
				s << ": " << reg(i_instr->fp_register);
				break;
			// DW_CFA_extended and DW_CFA_nop are the same value, BUT
			case DW_CFA_nop: goto no_args;      // this is a full zero byte
			// extended opcodes follow
			case DW_CFA_remember_state: goto no_args;
			case DW_CFA_restore_state: goto no_args;
			no_args:
				break;
			case DW_CFA_set_loc:
				goto unsupported_for_now; // FIXME
				break;

			case DW_CFA_offset_extended_sf: goto register_and_offset;
			case DW_CFA_def_cfa_sf: goto register_and_offset;
			case DW_CFA_register: goto register_and_offset;
			case DW_CFA_offset_extended: goto register_and_offset;
			case DW_CFA_def_cfa: goto register_and_offset;
			case DW_CFA_val_offset: goto register_and_offset;
			case DW_CFA_val_offset_sf: goto register_and_offset;
			register_and_offset: // FIXME: second register goes where? I've put it in fp_offset_or_block_len
				s << ": " << reg(i_instr->fp_register) << " ofs " << i_instr->fp_offset_or_block_len;
				break;

			case DW_CFA_def_cfa_offset_sf: goto offset_only;
			case DW_CFA_def_cfa_offset: goto offset_only;
			offset_only:
				s << ": " << i_instr->fp_offset_or_block_len;
				break;

			case DW_CFA_expression:
				goto unsupported_for_now; // FIXME

			case DW_CFA_def_cfa_expression: goto expression;
			case DW_CFA_val_expression: goto expression;
			expression:
				s << " (";
				print_in_readelf_style(s, encap::loc_expr(dbg, i_instr->fp_expr_block, i_instr->fp_offset_or_block_len));
				s << ")";
				break;

			default: goto unsupported_for_now;
			unsupported_for_now:
				s << "FIXME";
				break;
		}
		
		s << endl;
	}
}
开发者ID:stephenrkell,项目名称:libdwarfpp,代码行数:89,代码来源:fde-print.cpp


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