En simpel error handler<br /><br />error.h<br />[code]<br />#pragma once<br />#include &lt;string&gt;<br />#include &lt;windows.h&gt;<br />class error<br />{<br />public:<br />	error(void);<br />	~error(void);<br />	void addError(int errorPlace,std::string whatHappened,HWND hWnd);<br />	void addError(int errorPlace,std::string whatHappened);<br />private:<br />	template&lt;typename T&gt; std::string toStr(T var);<br />	std::string currentTime();<br />	std::string currentDate();<br />};<br />[/code]<br /><br />error.cpp<br />[code]<br />#include &quot;error.h&quot;<br />#include &lt;io.h&gt;<br />#include &lt;ios&gt;<br />#include &lt;sstream&gt;<br />#include &lt;fstream&gt;<br />#include &lt;direct.h&gt;<br />#include &lt;ctime&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;iostream&gt;<br /><br />template&lt;typename T&gt; std::string error::toStr(T var)<br />{<br />	std::ostringstream tmp;<br />	tmp &lt;&lt; var;<br />	return tmp.str();<br />}<br /><br /><br /><br />const char path&#91;] = &quot;error/test.txt&quot;;<br />const char folder&#91;] = &quot;error/&quot;;<br /><br />error::error(void)<br />{<br />	if(_access(path,0))<br />	{<br />		if(!_mkdir(&quot;error&quot;))<br />		{<br />			std::ofstream&nbsp; filestream(path);<br />			filestream.close();<br />		}<br />		else if(_access(path,0))<br />		{<br />			std::ofstream&nbsp; filestream(path);<br />			filestream.close();<br />		}<br />	}<br />}<br /><br /><br />error::~error(void)<br />{<br />}<br /><br /><br />//Man kan ta bort commentaren så kan man använda sig av denna när man håller på med ett win32 (EJ CONSOL) project med fönster<br />/*void error::addError(int errorPlace, std::string whatHappened, HWND hWnd)<br />{<br />	std::string errorFile = &quot;error/&quot;;													//bara för att börja sökvägen<br />	errorFile += currentDate();														//lägga till år/månad/datum/timmar/min/sek<br />	errorFile += &quot;.txt&quot;;															//Se till så att det blir en text fil<br />	if(!_access(&quot;error/&quot;,0))<br />	{<br /><br />		std::ofstream fileStream;<br />		fileStream.open(errorFile, std::ios_base::app);<br />		if(!fileStream.is_open())<br />		{<br />			if (hWnd)<br />			{<br />				MessageBox(NULL, L&quot;FileStream: Could not make file &quot;, L&quot;b4z44r Error&quot;, NULL);<br />			}<br />			fileStream.close();<br />		}<br />		else<br />		{<br />			fileStream &lt;&lt; currentTime()&nbsp; &lt;&lt; &quot; =&nbsp; &nbsp; &quot; &lt;&lt; toStr(errorPlace) &lt;&lt; &quot; : &quot; &lt;&lt; whatHappened &lt;&lt; &quot; &quot; &lt;&lt; std::endl;<br />			fileStream.close();<br />		}<br />	}<br />}*/<br /><br />void error::addError(int errorPlace, std::string whatHappened)<br />{<br />	std::string errorFile = &quot;error/&quot;;													//bara för att börja sökvägen<br />	errorFile += currentDate();														//lägga till år/månad/datum/timmar/min/sek<br />	errorFile += &quot;.txt&quot;;															//Se till så att det blir en text fil<br />	if(!_access(&quot;error/&quot;,0))<br />	{<br /><br />		std::ofstream fileStream(errorFile, std::ios_base::app);<br />		if(!fileStream.is_open())<br />		{<br />			fileStream.close();<br />		}<br />		else<br />		{<br />			fileStream &lt;&lt; currentTime()&nbsp; &lt;&lt; &quot; =&nbsp; &nbsp; &quot; &lt;&lt; toStr(errorPlace) &lt;&lt; &quot; : &quot; &lt;&lt; whatHappened &lt;&lt; &quot; &quot; &lt;&lt; std::endl;<br />			fileStream.close();<br />		}<br />	}<br />}<br /><br />std::string error::currentDate()<br />{<br />	time_t&nbsp; &nbsp;  now = time(0);								//gets the time<br />	struct tm&nbsp; tstruct;<br />	char&nbsp; &nbsp; &nbsp;  buf[80];<br />	tstruct = *localtime(&amp;now);<br /><br />	strftime(buf, sizeof(buf), &quot;%Y-%m-%d&quot;, &amp;tstruct);<br /><br />	return buf;<br />}<br /><br />std::string error::currentTime()<br />{<br />	time_t&nbsp; &nbsp;  now = time(0);								//gets the time<br />	struct tm&nbsp; tstruct;<br />	char&nbsp; &nbsp; &nbsp;  buf[80];<br />	tstruct = *localtime(&amp;now);<br /><br />	strftime(buf, sizeof(buf), &quot;%X&quot;, &amp;tstruct);<br /><br />	return buf;<br />}<br />[/code]