{"id":355246,"date":"2024-05-20T23:04:36","date_gmt":"2024-05-20T23:04:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=355246"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=355246","title":{"rendered":"<span>\u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430 C++ \u0441\u0442\u0430\u0440\u044b\u043c \u0438 \u043d\u043e\u0432\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/761910\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ck\/dk\/lt\/ckdkltwzaocqpwpfvoqerbmerja.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ck\/dk\/lt\/ckdkltwzaocqpwpfvoqerbmerja.png\"\/><\/div>\n<p><\/a><br \/>  \u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430 C++ \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0447\u0435\u0440\u0435\u0437 <code>std::stringstream<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>operator &lt;&lt;<\/code>);<\/li>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 <code>printf<\/code>, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>sprintf<\/code>;<\/li>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f C++20, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>std::format<\/code> \/ <code>std::format_to<\/code>;<\/li>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>{fmt}<\/code> (\u043e\u0441\u043d\u043e\u0432\u0430 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/li>\n<\/ul>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c. \u041d\u043e \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043b\u0443\u0447\u0448\u0435 \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438? \u042d\u0442\u043e \u044f \u0438 \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c.<a name=\"habracut\"><\/a><\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/font><\/h2>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0432\u0438\u0434\u0435 <code>\"severity=1,error=42,reason=access denied\"<\/code>. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  \u2022 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">int severity = 1; unsigned error = 42; reason = \"access denied\";  std::stringstream ss; ss &lt;&lt; \"severity=\" &lt;&lt; severity    &lt;&lt; \",error=\" &lt;&lt; error    &lt;&lt; \",reason=\" &lt;&lt; reason;  std::string text = ss.str();<\/code><\/pre>\n<p>  \u2022 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>printf<\/code>:<\/p>\n<pre><code class=\"cpp\">int severity = 1; unsigned error = 42; reason = \"access denied\";  std::string text(50, '\\0'); sprintf(text.data(), \"severity=%d,error=%u,reason=%s\", severity, error, reason);<\/code><\/pre>\n<p>  \u2022 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>format<\/code>:<\/p>\n<pre><code class=\"cpp\">int severity = 1; unsigned error = 42; reason = \"access denied\";  std::string text = std::format(\"severity={},error={},reason={}\", severity, error, reason);  \/\/ \u043b\u0438\u0431\u043e  std::string text; std::format_to(std::back_inserter(text), \"severity={},error={},reason={}\", severity, error, reason);<\/code><\/pre>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 <code>std::format<\/code> \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 <code>printf<\/code>, \u0445\u043e\u0442\u044f \u0437\u0434\u0435\u0441\u044c \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0442\u0438\u043f\u043e\u0432, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>%d<\/code>, <code>%u<\/code>, <code>%s<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>{}<\/code>. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0442\u0438\u043f\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u0438 \u043e \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/format\/formatter\">\u0442\u0443\u0442<\/a>, \u043d\u043e \u044d\u0442\u0430 \u0442\u0435\u043c\u0430 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0443\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 <code>std::format_to<\/code> \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0431\u0443\u0444\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435, \u0433\u0434\u0435 <code>reason<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0442\u043e-\u043b\u0438\u0431\u043e:<\/p>\n<pre><code class=\"cpp\">std::string text = std::format(\"severity={},error={}\", severity, error);  if(!reason.empty())   std::format_to(std::back_inserter(text), \",reason=\", reason);<\/code><\/pre>\n<h2><font color=\"#3AC1EF\">\u258d \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/font><\/h2>\n<p>  \u041f\u0440\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0430 \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043b\u0443\u0447\u0448\u0435? \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <code>{fmt}<\/code> \u2014 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e. \u041d\u043e \u043d\u0435 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0440\u0430\u0432\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u044b, \u0438 \u043e\u0431\u044b\u0447\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043d\u0435\u0441\u0442\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u0430 \u043d\u0435 \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0431\u0449\u0435\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0437\u0430\u0434\u0430\u043b \u0441\u0435\u0431\u0435 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u0432 \u0441\u0432\u043e\u0451\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043e\u0431\u0448\u0438\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>std::stringstream<\/code> \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0436\u0443\u0440\u043d\u0430\u043b\u0430. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0442\u0430\u043c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u043e \u0442\u0440\u0451\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">std::stringstream ss; ss &lt;&lt; \"component id: \" &lt;&lt; id;  std::string msg = ss.str();  \/\/ \u043b\u0438\u0431\u043e  std::stringstream ss; ss &lt;&lt; \"source: \" &lt;&lt; source &lt;&lt; \"|code=\" &lt;&lt; code;  std::string msg = ss.str();<\/code><\/pre>\n<p>  \u042f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0430 <code>std::stringstream<\/code> \u043d\u0430 <code>std::format<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438, \u043d\u043e \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u043e\u0446\u0435\u043d\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e. \u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0432 \u0432\u0438\u0434\u0435 <code>\"Number 42 is great!\"<\/code>;<\/li>\n<li>\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 <code>std::stringstream<\/code>, <code>sprintf, std::format<\/code> \u0438 <code>std::format_to<\/code>;<\/li>\n<li>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u043e\u0442 1 \u0434\u043e 1000000, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"cpp\">int main() {    {       std::stringstream ss;       ss &lt;&lt; 42;    }     using namespace std::chrono_literals;     std::random_device rd{};    auto mtgen = std::mt19937{ rd() };    auto ud = std::uniform_int_distribution&lt;>{ -1000000, 1000000 };     std::vector&lt;int> iterations{ 1, 2, 5, 10, 100, 1000, 10000, 100000, 1000000 };     std::println(\"{:>10} {:>12} {:>7} {:>9} {:>6}\", \"iterations\", \"stringstream\", \"sprintf\", \"format_to\", \"format\");    std::println(\"{:>10} {:>12} {:>7} {:>9} {:>6}\", \"----------\", \"------------\", \"-------\", \"---------\", \"------\");     for (int count : iterations)    {       std::vector&lt;int> numbers(count);       for (std::size_t i = 0; i &lt; numbers.size(); ++i)       {          numbers[i] = ud(mtgen);       }        long long t1, t2, t3, t4;        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::stringstream ss;             ss &lt;&lt; \"Number \" &lt;&lt; numbers[i] &lt;&lt; \" is great!\";             std::string s = ss.str();          }           auto end = std::chrono::high_resolution_clock::now();          t1 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string str(100, '\\0');             std::sprintf(str.data(), \"Number %d is great!\", numbers[i]);          }           auto end = std::chrono::high_resolution_clock::now();          t2 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string s;             std::format_to(std::back_inserter(s), \"Number {} is great!\", numbers[i]);          }           auto end = std::chrono::high_resolution_clock::now();          t3 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string s = std::format(\"Number {} is great!\", numbers[i]);          }           auto end = std::chrono::high_resolution_clock::now();          t4 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        std::println(\"{:&lt;10} {:&lt;12.2f} {:&lt;7.2f} {:&lt;9.2f} {:&lt;7.2f}\", count, t1\/1000.0 \/ count, t2 \/ 1000.0 \/ count, t3 \/ 1000.0 \/ count, t4 \/ 1000.0 \/ count);    } }<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d\u0430\u0445 \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043d\u044b\u043c\u0438. \u041d\u0430 \u043c\u043e\u0435\u0439 64-\u0431\u0438\u0442\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u044b\u0434\u0430\u0451\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (\u0432\u0440\u0435\u043c\u044f \u0432 \u043c\u043a\u0441):  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tbody>\n<tr>\n<td><b><font color=\"#3AC1EF\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">stringstream<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">sprintf<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">format_to<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">format<\/font><\/b><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>29.60 <\/td>\n<td>11.80<\/td>\n<td>1.80<\/td>\n<td>0.60<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>10.00 <\/td>\n<td>4.20<\/td>\n<td>0.55<\/td>\n<td>0.50<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>1.56 <\/td>\n<td>0.56<\/td>\n<td>0.34<\/td>\n<td>0.26<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>1.61 <\/td>\n<td>1.15<\/td>\n<td> 0.26<\/td>\n<td>0.31<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>1.15 <\/td>\n<td>0.28<\/td>\n<td>0.22<\/td>\n<td>0.26<\/td>\n<\/tr>\n<tr>\n<td>1000<\/td>\n<td>1.17 <\/td>\n<td>0.30<\/td>\n<td>0.24<\/td>\n<td>0.26<\/td>\n<\/tr>\n<tr>\n<td>10 000<\/td>\n<td>1.29 <\/td>\n<td>0.28<\/td>\n<td>0.23<\/td>\n<td>0.24<\/td>\n<\/tr>\n<tr>\n<td>100 000<\/td>\n<td>0.87 <\/td>\n<td>0.18<\/td>\n<td>0.15<\/td>\n<td>0.16<\/td>\n<\/tr>\n<tr>\n<td>1 000 000<\/td>\n<td>0.74 <\/td>\n<td>0.18<\/td>\n<td>0.15<\/td>\n<td>0.16<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u043d\u0430\u0442\u044c \u0446\u0438\u043a\u043b \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0442\u043e <code>sprintf<\/code>, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 2-3 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 <code>std::stringstream<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c <code>std::format<\/code>\/<code>std::format_to<\/code> \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u044e\u0442 <code>std::stringstream<\/code> \u0432 20-30 \u0440\u0430\u0437, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f\u0441\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 <code>sprintf<\/code> \u0432 5-20 \u0440\u0430\u0437. \u041f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u044d\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u043d\u043e <code>std::format<\/code> \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 5 \u0440\u0430\u0437 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 <code>std::stringstream<\/code> \u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0440\u0430\u0432\u043d\u0435 \u0441 <code>sprintf<\/code>. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435, \u044f \u043c\u043e\u0433\u0443 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c, \u0447\u0442\u043e \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c 20-30 \u043a\u0440\u0430\u0442.<\/p>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0433\u0434\u0430 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0445\u043e\u0436\u0438. \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 <code>\"Numbers 42 and 43 are great!\"<\/code> \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">int main() {    {       std::stringstream ss;       ss &lt;&lt; 42;    }     using namespace std::chrono_literals;     std::random_device rd{};    auto mtgen = std::mt19937{ rd() };    auto ud = std::uniform_int_distribution&lt;>{ -1000000, 1000000 };     std::vector&lt;int> iterations{ 1, 2, 5, 10, 100, 1000, 10000, 100000, 1000000 };     std::println(\"{:>10} {:>12} {:>7} {:>9} {:>6}\", \"iterations\", \"stringstream\", \"sprintf\", \"format_to\", \"format\");    std::println(\"{:>10} {:>12} {:>7} {:>9} {:>6}\", \"----------\", \"------------\", \"-------\", \"---------\", \"------\");     for (int count : iterations)    {       std::vector&lt;int> numbers(count);       for (std::size_t i = 0; i &lt; numbers.size(); ++i)       {          numbers[i] = ud(mtgen);       }        long long t1, t2, t3, t4;        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::stringstream ss;             ss &lt;&lt; \"Numbers \" &lt;&lt; numbers[i] &lt;&lt; \" and \" &lt;&lt; numbers[i] + 1 &lt;&lt; \" are great!\";             std::string s = ss.str();          }           auto end = std::chrono::high_resolution_clock::now();          t1 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string str(100, '\\0');             sprintf(str.data(), \"Numbers %d and %d are great!\", numbers[i], numbers[i] + 1);          }           auto end = std::chrono::high_resolution_clock::now();          t2 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string s;             std::format_to(std::back_inserter(s), \"Numbers {} and {} are great!\", numbers[i], numbers[i] + 1);          }           auto end = std::chrono::high_resolution_clock::now();          t3 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        {          auto start = std::chrono::high_resolution_clock::now();           for (std::size_t i = 0; i &lt; numbers.size(); ++i)          {             std::string s = std::format(\"Numbers {} and {} are great!\", numbers[i], numbers[i] + 1);          }           auto end = std::chrono::high_resolution_clock::now();          t4 = std::chrono::duration_cast&lt;std::chrono::nanoseconds>(end - start).count();       }        std::println(\"{:&lt;10} {:&lt;12.2} {:&lt;7.2} {:&lt;9.2} {:&lt;7.2}\", count, t1 \/ 1000.0 \/ count, t2 \/ 1000.0 \/ count, t3 \/ 1000.0 \/ count, t4 \/ 1000.0 \/ count);    } }<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435, \u0447\u0442\u043e \u0438 \u043f\u0440\u0435\u0436\u0434\u0435. \u0425\u043e\u0442\u044f, \u043e\u043f\u044f\u0442\u044c \u0436\u0435, \u043e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f:  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<tbody>\n<tr>\n<td><b><font color=\"#3AC1EF\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">stringstream<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">sprintf<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">format_to<\/font><\/b><\/td>\n<td><b><font color=\"#3AC1EF\">format<\/font><\/b><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>27 <\/td>\n<td>4.7<\/td>\n<td>5.8<\/td>\n<td>0.8<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>8.1 <\/td>\n<td>1.4<\/td>\n<td>0.9<\/td>\n<td>0.75<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>3.4 <\/td>\n<td>0.8<\/td>\n<td>0.62<\/td>\n<td>0.46<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>4.3 <\/td>\n<td>0.82<\/td>\n<td>0.44<\/td>\n<td>0.38<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>1.9 <\/td>\n<td>0.45<\/td>\n<td>0.31<\/td>\n<td>0.33<\/td>\n<\/tr>\n<tr>\n<td>1000<\/td>\n<td>1.9 <\/td>\n<td>0.46<\/td>\n<td>0.37<\/td>\n<td>0.35<\/td>\n<\/tr>\n<tr>\n<td>10 000<\/td>\n<td>1.8 <\/td>\n<td>0.38<\/td>\n<td>0.29<\/td>\n<td>0.31<\/td>\n<\/tr>\n<tr>\n<td>100 000<\/td>\n<td>1.3 <\/td>\n<td>0.26<\/td>\n<td>0.22<\/td>\n<td>0.24<\/td>\n<\/tr>\n<tr>\n<td>1 000 000<\/td>\n<td>1.2 <\/td>\n<td>0.27<\/td>\n<td>0.23<\/td>\n<td>0.25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><font color=\"#3AC1EF\">\u258d \u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c<\/font><\/h2>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 <code>std::stringstream<\/code> \u043d\u0430 <code>std::format<\/code> \u043b\u0435\u0433\u043a\u043e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0443\u0444\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">int a = 42;  std::stringstream ss; ss &lt;&lt; \"address=\" &lt;&lt; &amp;a; std::string text = ss.str();<\/code><\/pre>\n<p>  \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434 <code>\"address=00000004D4DAE218\"<\/code>. \u041d\u043e \u0441 <code>std::forma<\/code>t \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">int a = 42;  std::string text = std::format(\"address={}\", &amp;a); \/\/ \u043e\u0448\u0438\u0431\u043a\u0430; \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 (\u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430), \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0447\u0442\u043e \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>std::size_t<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a <code>:016X<\/code> (16 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 \u0441 \u0432\u0435\u0434\u0443\u0449\u0438\u043c\u0438 \u043d\u0443\u043b\u044f\u043c\u0438):<\/p>\n<pre><code class=\"cpp\">std::string text = std::format(\"address={:016X}\", reinterpret_cast&lt;std::size_t>(&amp;a));<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c (\u0445\u043e\u0442\u044f \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c 8 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0446\u0438\u0444\u0440).<\/p>\n<p>  \u0412\u043e\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <code>std::stringstream<\/code> \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0431\u0443\u0444\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432 <code>char<\/code>:<\/p>\n<pre><code class=\"cpp\">unsigned char str[]{3,4,5,6,0};  std::stringstream ss; ss &lt;&lt; \"str=\" &lt;&lt; str; std::string text = ss.str();<\/code><\/pre>\n<p>  \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u0442\u0435\u043a\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 <code>\"str=\u2665\u2666\u2663\u2660\"<\/code>.<\/p>\n<p>  \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>std::format<\/code> \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<pre><code class=\"cpp\">std::string text = std::format(\"str={}\", str); \/\/ \u043e\u0448\u0438\u0431\u043a\u0430; \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">std::string text = \"str=\"; for (auto c : str)    std::format_to(std::back_inserter(text), \"{}\", c);<\/code><\/pre>\n<p>  \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u0442\u0435\u043a\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 <code>\"str=34560\"<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 <code>unsigned char<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0431\u0443\u0444\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0431\u0435\u0437 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u0447\u0442\u043e \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044f\u0432\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">std::string text = \"str=\"; for (auto c : str)    std::format_to(std::back_inserter(text), \"{}\", static_cast&lt;char>(c));<\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u258d \u041a\u0441\u0442\u0430\u0442\u0438<\/font><\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442\u0435 \u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 <code>std::format<\/code> \/ <code>std::format_to<\/code> \u0447\u0435\u0440\u0435\u0437 <code>std::cout<\/code> (\u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b), \u0442\u043e \u0432 \u0421++23, \u0433\u0434\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c <code>std::print<\/code> \u0438 <code>std::println<\/code>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">int severity = 1; unsigned error = 42; reason = \"access denied\";  std::println(\"severity={},error={},reason={}\", severity, error, reason);<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p><b><font color=\"#3AC1EF\"><a href=\"https:\/\/t.me\/ruvds_community\">Telegram-\u043a\u0430\u043d\u0430\u043b \u0441 \u0440\u043e\u0437\u044b\u0433\u0440\u044b\u0448\u0430\u043c\u0438 \u043f\u0440\u0438\u0437\u043e\u0432, \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438 IT \u0438 \u043f\u043e\u0441\u0442\u0430\u043c\u0438 \u043e \u0440\u0435\u0442\u0440\u043e\u0438\u0433\u0440\u0430\u0445 ?\ufe0f<\/a><\/font><\/b><\/p><\/blockquote>\n<p><a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=Bright_Translate&amp;utm_content=formatirovanie_teksta_na_c_starym_i_novym_sposobom\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/tp\/sk\/z-\/tpskz-7w7a8e74isoowuep40xeg.png\" data-src=\"https:\/\/habrastorage.org\/webt\/tp\/sk\/z-\/tpskz-7w7a8e74isoowuep40xeg.png\"\/><\/a><\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/761910\/\"> https:\/\/habr.com\/ru\/articles\/761910\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/761910\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ck\/dk\/lt\/ckdkltwzaocqpwpfvoqerbmerja.png\" data-src=\"https:\/\/habrastorage.org\/webt\/ck\/dk\/lt\/ckdkltwzaocqpwpfvoqerbmerja.png\"\/><\/div>\n<p><\/a><br \/>  \u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430 C++ \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0447\u0435\u0440\u0435\u0437 <code>std::stringstream<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>operator &lt;&lt;<\/code>);<\/li>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 <code>printf<\/code>, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>sprintf<\/code>;<\/li>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f C++20, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>std::format<\/code> \/ <code>std::format_to<\/code>;<\/li>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 <code>{fmt}<\/code> (\u043e\u0441\u043d\u043e\u0432\u0430 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/li>\n<\/ul>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c. \u041d\u043e \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043b\u0443\u0447\u0448\u0435 \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438? \u042d\u0442\u043e \u044f \u0438 \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-355246","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=355246"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355246\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=355246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=355246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=355246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}