から取得した文字列がありますostringstream
。現在、この文字列 ( ) の一部の文字を置き換えようとしていますcontent.replace(content.begin(), content.end(), "\n", "");
が、例外が発生することがあります。
malloc: *** mach_vm_map(size=4294955008) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
std::bad_alloc
文字列が大きすぎるためにこれが発生すると思われます。これらの状況のベストプラクティスは何ですか? ヒープ上で文字列を宣言しますか?
アップデート
私の完全な方法:
xml_node HTMLDocument::content() const {
xml_node html = this->doc.first_child();
xml_node body = html.child("body");
xml_node section = body.child("section");
std::ostringstream oss;
if (section.type() != xml_node_type::node_null) {
section.print(oss);
} else {
body.print(oss);
}
string content;
content = oss.str();
content.replace(content.begin(), content.end(), "<section />", "<section></section>");
content.replace(content.begin(), content.end(), "\t", "");
xml_node node;
return node;
}