<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Reflections of a scattered Mind !! &#187; c++</title>
	<atom:link href="http://blog.saionline.co.in/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.saionline.co.in</link>
	<description>&#34;Not all scattered pieces are of broken glass&#34;</description>
	<lastBuildDate>Mon, 14 Nov 2011 20:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
<cloud domain='blog.saionline.co.in' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>C++ Quickies #I : Long live the STL</title>
		<link>http://blog.saionline.co.in/2010/09/c-quickies-i-long-live-the-stl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-quickies-i-long-live-the-stl</link>
		<comments>http://blog.saionline.co.in/2010/09/c-quickies-i-long-live-the-stl/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 05:42:47 +0000</pubDate>
		<dc:creator>Sai Prasad</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[stl]]></category>

		<guid isPermaLink="false">http://blog.saionline.co.in/?p=247</guid>
		<description><![CDATA[Its been quite some time (16+ months) I&#8217;ve been out of college and started using STL. Trust me, I didn&#8217;t know much about STL in college, though I used std::string &#38; std::vector everywhere I could. Now, it seems like I couldn&#8217;t (wouldn&#8217;t ? ) write a program without using STL at all. A few snippets  [...]]]></description>
			<content:encoded><![CDATA[<p>Its been quite some time (16+ months) I&#8217;ve been out of college and started using STL. Trust me, I didn&#8217;t know much about STL in college, though I used std::string &amp; std::vector everywhere I could. Now, it seems like I couldn&#8217;t (wouldn&#8217;t ? ) write a program without using STL at all. A few snippets that I really found useful (and simple) and I regularly use where ever possible.</p>
<p>To output the elements (all / subset) in a container (lets say vector), separated by a delimiter, say new line:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;algorithm&gt;

std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, &quot;\n&quot;));
</pre>
<p>Want to sort an array? No problem &#8230; <img src='http://blog.saionline.co.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: cpp; title: ; notranslate">

#include &lt;algorithm&gt;

std::sort(array, array + lengthOfArray);
</pre>
<p>Read from the standard input into a vector until the end-of-stream?</p>
<pre class="brush: cpp; title: ; notranslate">

#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;vector&gt;

typedef std::istream_iterator&lt;int&gt; istream_iterator_int;
std::vector&lt;int&gt; v;
istream_iterator_int start (std::cin);
istream_iterator_int end;
std::back_insert_iterator&lt;vector&lt;int&gt; &gt; dest (v);
std::copy (start, end, dest);
</pre>
<p>Count the no. of instances an object is found?</p>
<pre class="brush: cpp; title: ; notranslate">

#include &lt;algorithm&gt;

size_t count = std::count(v.begin(), v.end(), 42); // Returns no. of elements in v with value 42.
</pre>
<p>And let me inform you&#8230; This is just a grain of what STL can do&#8230;. <img src='http://blog.saionline.co.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>References:</p>
<p><a href="http://www.cs.brown.edu/~jak/proglang/cpp/stltut/tut.html">http://www.cs.brown.edu/~jak/proglang/cpp/stltut/tut.html</a></p>
<p><a href="http://www.cplusplus.com/reference/algorithm/">http://www.cplusplus.com/reference/algorithm/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.saionline.co.in/2010/09/c-quickies-i-long-live-the-stl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I had a problem</title>
		<link>http://blog.saionline.co.in/2009/12/i-had-a-problem/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=i-had-a-problem</link>
		<comments>http://blog.saionline.co.in/2009/12/i-had-a-problem/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 23:52:29 +0000</pubDate>
		<dc:creator>Sai Prasad</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[files]]></category>

		<guid isPermaLink="false">http://blog.saionline.co.in/?p=182</guid>
		<description><![CDATA[Symptoms: 

Language: C++, Operating System: Windows
Target Audience: Programmers
Sub Area: Reading ASCII / UTF-8 files from the disk using C++ streams.
Trouble: How to handle files whose file names contains non-ASCII characters?? (coz ifstream takes a ASCII file path   )

Solution:

Use  [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Symptoms: </strong></p>
<ul>
<li>Language: C++, Operating System: Windows</li>
<li>Target Audience: Programmers</li>
<li>Sub Area: Reading ASCII / UTF-8 files from the disk using C++ streams.</li>
<li>Trouble: How to handle files whose file names contains non-ASCII characters?? (coz ifstream takes a ASCII file path <img src='http://blog.saionline.co.in/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  )</li>
</ul>
<p><strong>Solution:</strong></p>
<ul>
<li>Use _wfopen_s(), the safe version of _wfopen(), which takes a wide-character file name &amp; gives a FILE pointer i.e; FILE*.</li>
<li>Use the obtained FILE* to create a stream, like ifstream in(fp);</li>
<li>We used wide-character file name &amp; are reading the file byte-by-byte (actually, its char). DONE !! <img src='http://blog.saionline.co.in/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<p>BTW, I got help from <a href="http://bytes.com/topic/net/answers/264598-iostream-question-how-open-unicode-file-name">here</a> ! Hope this saves  time for someone out there&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.saionline.co.in/2009/12/i-had-a-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

