<?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>Highub &#187; C++</title>
	<atom:link href="http://www.highub.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.highub.com</link>
	<description>Answers to all your programming questions</description>
	<lastBuildDate>Mon, 09 Aug 2010 05:00:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>FileStream StreamReader in C#</title>
		<link>http://www.highub.com/filestream-streamreader-in-c/</link>
		<comments>http://www.highub.com/filestream-streamreader-in-c/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 10:42:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C Sharp]]></category>

		<guid isPermaLink="false">http://www.highub.com/?p=27</guid>
		<description><![CDATA[One way to go in a file and read the lines in C# is to use FileStream and StreamReader together, you should always use while loop instead of for loop, otherwise, you will get the error I keep getting for this is: Cannot convert type &#8216;char&#8217; to &#8216;string&#8217;. using System; using System.Collections.Generic; using System.Linq; using [...]]]></description>
			<content:encoded><![CDATA[<p>One way to go in a file and read the lines in C# is to use FileStream and StreamReader together, you should always use while loop instead of for loop, otherwise, you will get the error I keep getting for this is: Cannot convert type &#8216;char&#8217; to &#8216;string&#8217;.</p>
<pre class="brush: plain;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace testing
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string file = @&quot;C:\Temp\New Folder\New Text Document.txt&quot;;
            using(FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                using(StreamReader sr = new StreamReader(fs))
                {
                    while(!sr.EndOfStream)
                    {
                       Console.WriteLine(sr.ReadLine());
                    }
                }
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.highub.com/filestream-streamreader-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding all factors of a given number in C#</title>
		<link>http://www.highub.com/finding-all-factors-of-a-given-number-in-c/</link>
		<comments>http://www.highub.com/finding-all-factors-of-a-given-number-in-c/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 10:30:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C Sharp]]></category>

		<guid isPermaLink="false">http://www.highub.com/?p=25</guid>
		<description><![CDATA[To find all factors of a given number in C# can be done using many different ways. A lean way of doing so is: Loop from 1 to the square root of the number, call the index &#8220;i&#8221;. if number mod i is 0, add i and number / i to the list of factors. [...]]]></description>
			<content:encoded><![CDATA[<p>To find all factors of a given number in C# can be done using many different ways. A lean way of doing so is:</p>
<ul>
<li>Loop from 1 to the square root of the number, call the index &#8220;i&#8221;.</li>
<li>if number mod i is 0, add i and number / i to the list of factors.</li>
</ul>
<pre class="brush: plain;">
public List&lt;int&gt; Factor(int number) {
    List&lt;int&gt; factors = new List&lt;int&gt;();
    int max = (int)Math.Sqrt(number);  //round down
    for(int factor = 1; factor &lt;= max; ++factor) { //test from 1 to the square root, or the int below it, inclusive.
        if(number % factor == 0) {
            factors.add(factor);
            if(factor != max) { // Don't add the square root twice!  Thanks Jon
                factors.add(number/factor);
            }
        }
    }
    return factors;
}
</pre>
<p>There are many other ways you could explore. You could implement this as an IEnumerable&#60;int&#62; as well &#8211; use yield instead of adding to a list. The advantage with List&#60;int&#62; is that it could be sorted before return if required. Then again, you could get a sorted enumerator with a hybrid approach, yielding the first factor and storing the second one in each iteration of the loop, then yielding each value that was stored in reverse order.</p>
<p>You will also want to do something to handle the case where a negative number passed into the function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.highub.com/finding-all-factors-of-a-given-number-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Windows shell environment variables from C++</title>
		<link>http://www.highub.com/changing-windows-shell-environment-variables-from-c/</link>
		<comments>http://www.highub.com/changing-windows-shell-environment-variables-from-c/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 19:25:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.highub.com/?p=16</guid>
		<description><![CDATA[A common technique to change Windows shell environment variables from C++ is the write an env file, that is then &#8220;called&#8221; from the script. del env.var foo.exe ## writes to env.var call env.var]]></description>
			<content:encoded><![CDATA[<p>A common technique to change Windows shell environment variables from C++ is the write an env file, that is then &#8220;called&#8221; from the script.</p>
<pre class="brush: plain;">
del env.var
foo.exe ## writes to env.var
call env.var
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.highub.com/changing-windows-shell-environment-variables-from-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
