{"id":196,"date":"2010-11-20T16:09:23","date_gmt":"2010-11-20T21:09:23","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=196"},"modified":"2010-11-20T16:09:23","modified_gmt":"2010-11-20T21:09:23","slug":"converting-between-int-and-string-in-c","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2010\/11\/20\/converting-between-int-and-string-in-c\/","title":{"rendered":"Converting between int and std::string in C++"},"content":{"rendered":"<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;cstdlib&gt;\r\nusing namespace std;\r\n\r\nint main() {\r\n\t\/\/ convert int to string\r\n\tint some_int = 52;\r\n\tstringstream ss;\r\n\tss &lt;&lt; some_int;\r\n\tstring result_s;\r\n\tss &gt;&gt; result_s;\r\n\t\/\/ result_s = 52\r\n\tcout &lt;&lt; result_s &lt;&lt; endl;\r\n\r\n\t\/\/ convert string to int\r\n\tstring some_string = &quot;1234&quot;;\r\n\tint result_i = atoi(some_string.c_str());\r\n\t\/\/ result_i = 1234\r\n\tcout &lt;&lt; result_i &lt;&lt; endl;\r\n}\r\n<\/pre>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4],"tags":[289,93,614,730,732,731],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/196"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}