<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>reading text file</title>
		<link>http://www.allegro.cc/forums/view/591824</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 12 Jun 2007 10:38:47 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hey,<br />For the last few days I&#39;ve been working on my first game which is a simple arcade game and im basically finished but iv just got to add a very simple highscore system.</p><p>I&#39;ve managed to get the code to write to the highscore file:</p><p>   ofstream file(&quot;highscore.txt&quot;);<br />   file &lt;&lt; score;</p><p>But I cant find out how I would load what i&#39;ve saved into the variable highscore.</p><p>please help:)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jools64)</author>
		<pubDate>Sun, 10 Jun 2007 07:02:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You just do the opposite. Open a file in output( I think) mode, then file &gt;&gt; score or whatever other variable you&#39;re using.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SonShadowCat)</author>
		<pubDate>Sun, 10 Jun 2007 08:23:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, without outputting spaces, that won&#39;t go over well. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> But basically, yeah.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sun, 10 Jun 2007 08:32:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>could you give me the code to do that?<br />thanks:)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jools64)</author>
		<pubDate>Sun, 10 Jun 2007 19:59:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.cplusplus.com/doc/tutorial/files.html">http://www.cplusplus.com/doc/tutorial/files.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sun, 10 Jun 2007 20:04:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried this:</p><p>  string line;<br />  ifstream file (&quot;highscore.txt&quot;);<br />  if (file.is_open())<br />  {<br />    while (! file.eof() )<br />    {<br />    getline (file,line);<br />    textprintf_ex( buffer, font, 300, 300, makecol(255, 255, 255),-1, &quot;Highscore: %d&quot;, line);<br />    }<br />    file.close();<br />  }</p><p>It compiles fine but when I run it I get <br />Super Jet Pack Boy.exe has encountered a problem and needs to close.  We are sorry for the inconvenience.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jools64)</author>
		<pubDate>Sun, 10 Jun 2007 20:24:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This probably isn&#39;t the source of the crash, but in the <tt>textprintf_ex()</tt> call, you tell it to expect an integer, and then pass a string.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sun, 10 Jun 2007 20:30:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre>string <a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">;</span>
ifstream file <span class="k2">(</span><span class="s">"highscore.txt"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span>file.is_open<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="k2">{</span>
<span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span> file.eof<span class="k2">(</span><span class="k2">)</span> <span class="k2">)</span>
<span class="k2">{</span>
getline <span class="k2">(</span>file,<a href="http://www.allegro.cc/manual/line" target="_blank"><span class="a">line</span></a><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/textprintf_ex" target="_blank"><span class="a">textprintf_ex</span></a><span class="k2">(</span> buffer, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="n">300</span>, <span class="n">300</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">255</span><span class="k2">)</span>,<span class="k3">-</span><span class="n">1</span>, <span class="s">"Highscore: %s"</span>, line.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
file.close<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Sun, 10 Jun 2007 21:49:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Dustin Dettmer it worked =D
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jools64)</author>
		<pubDate>Sun, 10 Jun 2007 22:09:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To be fair you should be thanking LennyLen, as we pretty much said the same thing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Sun, 10 Jun 2007 22:11:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thanks LennyLen too, sorry I did&#39;nt see your other reply.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jools64)</author>
		<pubDate>Sun, 10 Jun 2007 22:16:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t use that in an Allegro program.<br />line is already declared by Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Mon, 11 Jun 2007 12:43:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is the code I give my students to handle high scores.<br /><a href="http://www.timorg.net/high_score.zip">http://www.timorg.net/high_score.zip</a><br />If you are interested but have problems, post here or msg me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Timorg)</author>
		<pubDate>Mon, 11 Jun 2007 13:12:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Timorg: It&#39;s amazing how similar your code is to mine <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /><br />Just wondering: Why are you using so many c-isms in a c++ code? And if this code is intended to be an example, I&#39;d suggest to avoid magic numbers in your code and either #define or const the appropriate numerals.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Mon, 11 Jun 2007 15:48:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why would you ever use const?<br />Just wondering...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Mon, 11 Jun 2007 17:39:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why would you ever use const?
</p></div></div><p>
Maybe to indicate a constant? It also makes your code more easy to read / maintain.<br />Or do you want to know when to use const instead of a define?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Mon, 11 Jun 2007 17:42:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah.<br />I don&#39;t see the advantage, surely define is faster since it&#39;s done by the preprocessor...?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Mon, 11 Jun 2007 17:45:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, there shouldn&#39;t be a speed difference at all. The main reason to use const is that it is known at compile time. So you&#39;ll see the constants in error messages or while debugging.<br />Also, you can avoid some pitfalls using const:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define FOO 10</span>

<span class="c">/* oups... forgot to add brackets here, but who cares */</span>
<span class="p">#define BAR FOO+1</span>
<span class="p">#define BAZ 2* BAR</span>

<span class="c">/* BAZ is now: 2 * 10 +1 = 21</span>
<span class="c"> * instead of 2*BAR (= 2*11)</span>
<span class="c"> */</span>
</pre></div></div><p>

You can avoid the problem if you place all your defines in () but this can be forgotten. </p><p>It&#39;s also considered the better &quot;C++&quot; style.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Mon, 11 Jun 2007 17:58:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Defines won&#39;t give an error (except for random screwed up ones) if you have a naming conflict whereas consts will.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Mon, 11 Jun 2007 22:06:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>IMO naming conflicts is the main reason to not use macros.  Naming conflicts were sent here by the devil (just think of winalleg.h X[)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Tue, 12 Jun 2007 08:13:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">spellcaster said:</div><div class="quote"><p>

@Timorg: It&#39;s amazing how similar your code is to mine <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /><br />Just wondering: Why are you using so many c-isms in a c++ code? And if this code is intended to be an example, I&#39;d suggest to avoid magic numbers in your code and either #define or const the appropriate numerals
</p></div></div><p>

Our code being similar just means that it is being done in the right way. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I wrote that original code back in 2000 for a class assignment, It didn&#39;t have any error checking, it was just the basic code, and I shared it with the other people in the subject, 3 people got in trouble for plagarism, because they didn&#39;t site my code where everyone else did.</p><p>As for the C-isms, I guess I am a C programer at heart, but the code was for visual studio 6, and combining C and C++ code is a pain, so its basically C code in a cpp file. I only really use C++ for classes and the stl, everything else is done in C. I also don&#39;t really understand iostream for binary files, its just quicker and simpler for me to use the C functions to do it. And stl sorts arnt as simple as the qsort function.</p><p>As for magic numbers, yeah I should have used constants for the length, cause I remember old amiga games with scrolling highscores that go up from 100, and to change that you need to change values in a few places, where there should just be a const in the header.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Timorg)</author>
		<pubDate>Tue, 12 Jun 2007 10:38:47 +0000</pubDate>
	</item>
</rss>
