<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-28016235.post114795735036390575..comments</id><updated>2010-03-09T11:13:43.097-05:00</updated><title type='text'>Comments on Senzee 5: Formatting std::string</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.senzee5.com/feeds/114795735036390575/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html'/><author><name>Senzee</name><uri>http://www.blogger.com/profile/02573580670699332421</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-28016235.post-4009990634366658361</id><published>2010-03-09T11:13:43.089-05:00</published><updated>2010-03-09T11:13:43.089-05:00</updated><title type='text'>thanks a lot!

i'd just like to add one function t...</title><content type='html'>thanks a lot!&lt;br /&gt;&lt;br /&gt;i&amp;#39;d just like to add one function to pass the first length of result to try :)&lt;br /&gt;&lt;br /&gt;std::string format_arg_list(DWORD dwdResLenToTryFirst,const char *fmt, va_list args)&lt;br /&gt;{&lt;br /&gt; if(!fmt)return&amp;quot;&amp;quot;;&lt;br /&gt; int result=-1;&lt;br /&gt; int length=dwdResLenToTryFirst;&lt;br /&gt; char *buffer=0;&lt;br /&gt; while(result==-1)&lt;br /&gt; {&lt;br /&gt;  if(buffer)delete[]buffer;&lt;br /&gt;  buffer=new char[length+1];&lt;br /&gt;  memset(buffer,0,length+1);&lt;br /&gt;  result=_vsnprintf(buffer,length,fmt,args);&lt;br /&gt;  length *= 2;&lt;br /&gt; }&lt;br /&gt; std::string s(buffer);&lt;br /&gt; delete[]buffer;&lt;br /&gt; return s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;std::string format(const char *fmt, ...)&lt;br /&gt;{&lt;br /&gt; va_list args;&lt;br /&gt; va_start(args, fmt);&lt;br /&gt; std::string s=format_arg_list(256,fmt,args);&lt;br /&gt; va_end(args);&lt;br /&gt; return s;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;std::string formatLen(DWORD dwdResLenToTryFirst,const char *fmt, ...)&lt;br /&gt;{&lt;br /&gt; va_list args;&lt;br /&gt; va_start(args, fmt);&lt;br /&gt; std::string s=format_arg_list(dwdResLenToTryFirst,fmt,args);&lt;br /&gt; va_end(args);&lt;br /&gt; return s;&lt;br /&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/4009990634366658361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/4009990634366658361'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1268151223089#c4009990634366658361' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-6386997218084114795</id><published>2010-02-09T00:44:08.333-05:00</published><updated>2010-02-09T00:44:08.333-05:00</updated><title type='text'>If you are using VC, the _vsctprintf function will...</title><content type='html'>If you are using VC, the _vsctprintf function will give you the length need to store the resulting string, and you can get rid of the loop.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/6386997218084114795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/6386997218084114795'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1265694248333#c6386997218084114795' title=''/><author><name>Sean</name><uri>http://www.blogger.com/profile/11867211258829909666</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-7276926810038629240</id><published>2010-01-20T11:59:35.917-05:00</published><updated>2010-01-20T11:59:35.917-05:00</updated><title type='text'>It's so great that std::string doesn't have format...</title><content type='html'>It&amp;#39;s so great that std::string doesn&amp;#39;t have formatting. Just another evidence that c++ designers hadn&amp;#39;t coded a single line in ten years.&lt;br /&gt;&lt;br /&gt;My expectation level for tr1 is even higher, it so promising that I&amp;#39;ll probably change C++ for cobol, or something worse.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/7276926810038629240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/7276926810038629240'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1264006775917#c7276926810038629240' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-1854770620535074843</id><published>2009-09-23T11:34:23.624-04:00</published><updated>2009-09-23T11:34:23.624-04:00</updated><title type='text'>it's gcc ver..

http://blog.yurihan.net/entry/stds...</title><content type='html'>it&amp;#39;s gcc ver..&lt;br /&gt;&lt;br /&gt;http://blog.yurihan.net/entry/stdstring%EC%9D%98-formating-%EC%8B%9C%EB%B0%9C-%EB%82%9A%EC%98%80%EB%8B%A4</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/1854770620535074843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/1854770620535074843'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1253720063624#c1854770620535074843' title=''/><author><name>YuriHan's DreamFactory™</name><uri>http://www.blogger.com/profile/18383607312885778076</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-5931077729229301755</id><published>2009-03-20T02:56:00.000-04:00</published><updated>2009-03-20T02:56:00.000-04:00</updated><title type='text'>Thanks a million!!</title><content type='html'>Thanks a million!!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5931077729229301755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5931077729229301755'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1237532160000#c5931077729229301755' title=''/><author><name>Steve</name><uri>http://hendersons.info</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-3182058015696415049</id><published>2009-01-19T11:40:00.000-05:00</published><updated>2009-01-19T11:40:00.000-05:00</updated><title type='text'>Exactly what I was looking for ...Thank you !</title><content type='html'>Exactly what I was looking for ...&lt;BR/&gt;&lt;BR/&gt;Thank you !</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/3182058015696415049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/3182058015696415049'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1232383200000#c3182058015696415049' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-5583157861072477013</id><published>2008-01-27T09:07:00.000-05:00</published><updated>2008-01-27T09:07:00.000-05:00</updated><title type='text'>Thanks! This is great!</title><content type='html'>Thanks! This is great!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5583157861072477013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5583157861072477013'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1201442820000#c5583157861072477013' title=''/><author><name>Rick Companje</name><uri>http://www.blogger.com/profile/14916959056311391289</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-5868067961999723129</id><published>2007-11-30T17:08:00.000-05:00</published><updated>2007-11-30T17:08:00.000-05:00</updated><title type='text'>As you say, it's not the most efficient piece of c...</title><content type='html'>As you say, it's not the most efficient piece of code, but it is just in turn of a very nice and simple usage, just what I was looking for... &lt;BR/&gt;&lt;BR/&gt;Thank you very much!!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5868067961999723129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/5868067961999723129'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1196460480000#c5868067961999723129' title=''/><author><name>spanish coder</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-7717972270635422434</id><published>2007-10-25T06:12:00.000-04:00</published><updated>2007-10-25T06:12:00.000-04:00</updated><title type='text'>Thanks. What a nice!In visual Studio 2005, this co...</title><content type='html'>Thanks. What a nice!&lt;BR/&gt;In visual Studio 2005, this code meets deprecate warning.&lt;BR/&gt;So, I replace _vsnprintf to _vsprintf_s&lt;BR/&gt;&lt;BR/&gt;code :&lt;BR/&gt;result = _vsnprintf_s(buffer, length, _TRUNCATE, fmt, args);</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/7717972270635422434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/7717972270635422434'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1193307120000#c7717972270635422434' title=''/><author><name>darkblitz</name><uri>darkblitz.tistory.com</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-3905664510816790077</id><published>2007-07-26T10:45:00.000-04:00</published><updated>2007-07-26T10:45:00.000-04:00</updated><title type='text'>Because the return type is [std::string] and not [...</title><content type='html'>Because the return type is [std::string] and not [std::string &amp;] (or [std::string *]), it is return by value.  So, upon return, it will create a copy of the stack variable s in the caller's scope.&lt;BR/&gt;&lt;BR/&gt;So it's completely safe.&lt;BR/&gt;&lt;BR/&gt;Keep in mind however, that this is &lt;I&gt;not&lt;/I&gt; an efficient piece of code.  It's brute force and requires a number of allocations.  Still, it's convenient, and that's often more important than efficiency.&lt;BR/&gt;&lt;BR/&gt;Regarding the earlier comment about not supporting &lt;I&gt;unicode&lt;/I&gt; - that's true, but little modification is required for unicode support, such as using std::basic_string&amp;lt;wchar_t&amp;gt; instead of std::string and using the appropriate wide character formatting function.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/3905664510816790077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/3905664510816790077'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1185461100000#c3905664510816790077' title=''/><author><name>Senzee</name><uri>http://www.blogger.com/profile/02573580670699332421</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='03897801376978856190'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-8880149542639727862</id><published>2007-07-26T04:59:00.000-04:00</published><updated>2007-07-26T04:59:00.000-04:00</updated><title type='text'>std::string s(buffer);    delete [] buffer;    ret...</title><content type='html'>std::string s(buffer);    delete [] buffer;    return s;&lt;BR/&gt;}&lt;BR/&gt;&lt;BR/&gt;&lt;BR/&gt;Won't that give problems? Isn't "s" created on the heap and no longer guaranteed when the function returns (although it will _probably_ be there , just cos it isn't overwritten yet (espeically in non-threaded programs))?&lt;BR/&gt;&lt;BR/&gt;Does your compiler give warnigs? Did you run Lint on it?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/8880149542639727862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/8880149542639727862'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1185440340000#c8880149542639727862' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-385962184205535320</id><published>2007-06-11T07:46:00.000-04:00</published><updated>2007-06-11T07:46:00.000-04:00</updated><title type='text'>cool, but it seems that doest not support UNICODE....</title><content type='html'>cool, but it seems that doest not support UNICODE.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/385962184205535320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/385962184205535320'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1181562360000#c385962184205535320' title=''/><author><name>Perseus</name><uri>http://www.blogger.com/profile/16642515426991345939</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-116484589866118799</id><published>2006-11-29T19:18:00.000-05:00</published><updated>2006-11-29T19:18:00.000-05:00</updated><title type='text'>Thanks, not exactly how I thought it would be solv...</title><content type='html'>Thanks, not exactly how I thought it would be solved. But it works. Thanks.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/116484589866118799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/116484589866118799'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1164845880000#c116484589866118799' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-28016235.post-115791453124625965</id><published>2006-09-10T14:55:00.000-04:00</published><updated>2006-09-10T14:55:00.000-04:00</updated><title type='text'>Very nice piece of code. Saved me some time. Many ...</title><content type='html'>Very nice piece of code. Saved me some time. Many thanks!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/115791453124625965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28016235/114795735036390575/comments/default/115791453124625965'/><link rel='alternate' type='text/html' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html?showComment=1157914500000#c115791453124625965' title=''/><author><name>snake</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.senzee5.com/2006/05/c-formatting-stdstring.html' ref='tag:blogger.com,1999:blog-28016235.post-114795735036390575' source='http://www.blogger.com/feeds/28016235/posts/default/114795735036390575' type='text/html'/></entry></feed>