本文整理汇总了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);
}
示例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;
}
}