<?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>spechal.com &#187; C++</title>
	<atom:link href="http://spechal.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://spechal.com</link>
	<description>[spesh-uhl]</description>
	<lastBuildDate>Thu, 21 Jan 2010 11:50:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C++ Read from a file using fstream</title>
		<link>http://spechal.com/2009/11/16/c-read-from-a-file-using-fstream/</link>
		<comments>http://spechal.com/2009/11/16/c-read-from-a-file-using-fstream/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:32:59 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=42</guid>
		<description><![CDATA[
/**
  Read from a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &#60;iostream&#62;
#include &#60;fstream&#62;
#include &#60;string&#62;

int main(int argc, char* argv[]){

  // create the file handle, opening the file
  std::fstream myFile(&#34;text.txt&#34;, std::ios::in);

  // create a string to hold the line
  std::string line;

  if(myFile.is_open()){
 [...]]]></description>
			<content:encoded><![CDATA[<pre class="cpp" name="code">
/**
  Read from a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

int main(int argc, char* argv[]){

  // create the file handle, opening the file
  std::fstream myFile(&quot;text.txt&quot;, std::ios::in);

  // create a string to hold the line
  std::string line;

  if(myFile.is_open()){
    while(!myFile.eof()){
      getline(myFile, line);
      std::cout &lt;&lt; line &lt;&lt; std::endl;
    }
  } else {
    std::cout &lt;&lt; &quot;Could not open text.txt for reading.&quot; &lt;&lt; std::endl;
    return -1;
  }

  return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/16/c-read-from-a-file-using-fstream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Write to a file using fstream</title>
		<link>http://spechal.com/2009/11/16/c-write-to-a-file-using-fstream/</link>
		<comments>http://spechal.com/2009/11/16/c-write-to-a-file-using-fstream/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:26:56 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=40</guid>
		<description><![CDATA[
/**
  Write to a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &#60;iostream&#62;
#include &#60;fstream&#62;

int main(int argc, char* argv[]){

  // create the file handle, opening the file as well
  std::fstream myFile(&#34;text.txt&#34;, std::ios::out);

  if(myFile.is_open()){
    myFile &#60;&#60; &#34;I am just some text in [...]]]></description>
			<content:encoded><![CDATA[<pre class="cpp" name="code">
/**
  Write to a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &lt;iostream&gt;
#include &lt;fstream&gt;

int main(int argc, char* argv[]){

  // create the file handle, opening the file as well
  std::fstream myFile(&quot;text.txt&quot;, std::ios::out);

  if(myFile.is_open()){
    myFile &lt;&lt; &quot;I am just some text in some file.&quot;;
    myFile.close();
    std::cout &lt;&lt; &quot;File written to.&quot; &lt;&lt; std::endl;
  } else {
    // could not create/write to file
    std::cout &lt;&lt; &quot;Could not write to file.&quot; &lt;&lt; std::endl;
    return -1;
  }

  return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/16/c-write-to-a-file-using-fstream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Palindrome Checker</title>
		<link>http://spechal.com/2009/11/16/c-palindrome-checker/</link>
		<comments>http://spechal.com/2009/11/16/c-palindrome-checker/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 13:48:38 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=32</guid>
		<description><![CDATA[
/**
  Palindrome Checker
  Copyright 2009 Travis Crowder
  Published under the MIT License
*/

#include &#60;iostream&#62;
#include &#60;algorithm&#62;
#include &#60;string&#62;

bool isPalindrome(const std::string theWord);

int main(int argc, char* argv[]){

  std::string theWord;

  if(!argv[1]){
    std::cout &#60;&#60; &#34;Enter the word to check: &#34;;
    std::cin &#62;&#62; theWord;
  } else {
    theWord [...]]]></description>
			<content:encoded><![CDATA[<pre class="cpp" name="code">
/**
  Palindrome Checker
  Copyright 2009 Travis Crowder
  Published under the MIT License
*/

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;string&gt;

bool isPalindrome(const std::string theWord);

int main(int argc, char* argv[]){

  std::string theWord;

  if(!argv[1]){
    std::cout &lt;&lt; &quot;Enter the word to check: &quot;;
    std::cin &gt;&gt; theWord;
  } else {
    theWord = argv[1];
  }
  std::cout &lt;&lt; std::endl;

  /**
    Make all of the characters lower case
  */
  int i = 0;
  while(theWord[i]){
    if(isupper(theWord[i]))
      theWord[i] = tolower(theWord[i]);
    i++;
  }

  std::cout &lt;&lt; theWord &lt;&lt; &quot; is &quot;;
  if(!isPalindrome(theWord))
    std::cout &lt;&lt; &quot;NOT &quot;;
  std::cout &lt;&lt; &quot;a palindrome.&quot; &lt;&lt; std::endl;
  return 0;
}

bool isPalindrome(const std::string theWord){
  std::string tmp = theWord;
  reverse(tmp.begin(), tmp.end());
  if(tmp == theWord)
    return true;
  return false;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/16/c-palindrome-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Simple Temperature Converter</title>
		<link>http://spechal.com/2009/11/15/c-simple-temperature-converter/</link>
		<comments>http://spechal.com/2009/11/15/c-simple-temperature-converter/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 21:20:06 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=20</guid>
		<description><![CDATA[
/**
  Temperature Converter
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/

#include &#60;iostream&#62;

int main(int argc, char* argv[]){

  /**
    Create a variable to hold the input temperature value
  */
  double input = NULL;

  /**
    Create a variable to hold the output [...]]]></description>
			<content:encoded><![CDATA[<pre class="cpp" name="code">
/**
  Temperature Converter
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/

#include &lt;iostream&gt;

int main(int argc, char* argv[]){

  /**
    Create a variable to hold the input temperature value
  */
  double input = NULL;

  /**
    Create a variable to hold the output temperature value
  */
  double output = 0;

  /**
    Create a variable to hold which type we are converting from
  */
  char convFrom;
  /**
    Create a variable to hold which type we are converting to
  */
  char convTo;

  while(input == NULL){
    std::cout &lt;&lt; &quot;Enter the source temperature, without the type: &quot;;
    std::cin &gt;&gt; input;
    std::cout &lt;&lt; std::endl;
  }

  while(convFrom != 'C' &amp;&amp; convFrom != 'F'){
    std::cout &lt;&lt; &quot;What is the source temperature type?&quot; &lt;&lt; std::endl;
    std::cout &lt;&lt; &quot;[C]entigrade&quot; &lt;&lt; std::endl;
    std::cout &lt;&lt; &quot;[F]ahrenheit&quot; &lt;&lt; std::endl;
    std::cin &gt;&gt; convFrom;
  }

  /**
    Output the results
  */
  std::cout &lt;&lt; &quot;Your converted temperature is: &quot;;
  if(convFrom == 'F'){
    output = (input - 32) * 5 / 9;
    convTo = 'C';
  } else {
    output = (input * 9 / 5) + 32;
    convTo = 'F';
  }
  std::cout &lt;&lt; output &lt;&lt; convTo &lt;&lt; std::endl;

  return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/15/c-simple-temperature-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Guessing Game</title>
		<link>http://spechal.com/2009/11/15/c-guessing-game/</link>
		<comments>http://spechal.com/2009/11/15/c-guessing-game/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 20:52:12 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=18</guid>
		<description><![CDATA[
/**
  Guessing Game
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &#60;iostream&#62;

int main(int argc, char* argv[]){

  /**
    Create our variable to hold the guess made
  */
  int guess = 0;

  /**
    Let's keep track of the number of guesses [...]]]></description>
			<content:encoded><![CDATA[<pre class="cpp" name="code">
/**
  Guessing Game
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include &lt;iostream&gt;

int main(int argc, char* argv[]){

  /**
    Create our variable to hold the guess made
  */
  int guess = 0;

  /**
    Let's keep track of the number of guesses made.
  */
  int guesses = 0;

  /**
    Set the secret to be a random number between 1 and 100
    Remember to seed the random number generator
  */
  srand(time(0));
  int secret = rand() % 100 + 1;

  /**
    while our guess is not the secret, get a guess
  */
  while(guess != secret){
    std::cout &lt;&lt; &quot;Enter your guess, between 1 and 100: &quot;;
    std::cin &gt;&gt; guess;
    guesses++;
    if(guess == secret){
      /** guess was correct */
      std::cout &lt;&lt; &quot;You've figured out the secret in &quot; &lt;&lt; guesses;
      if(guesses == 1)
        std::cout &lt;&lt; &quot; guess&quot;;
      else
        std::cout &lt;&lt; &quot; guesses&quot;;
      std::cout &lt;&lt; &quot;!  It was &quot; &lt;&lt; secret &lt;&lt; &quot;!&quot; &lt;&lt; std::endl;
    } else if(guess &gt; secret){
      /** guess was too high */
      std::cout &lt;&lt; &quot;Your guess was too high!  Try again!&quot; &lt;&lt; std::endl;
    } else {
      /** our guess can only be lower, logically */
      std::cout &lt;&lt; &quot;Your guess was too low!  Try again!&quot; &lt;&lt; std::endl;
    }
  }

  return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/15/c-guessing-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
