<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[File schreiben, keine newline]]></title><description><![CDATA[<p>Hi zusammen</p>
<p>Hab wieder einmal eine Frage.</p>
<p>Mein Problem ist, dass ich eine Funktion habe, die mir einen string zurückgibt. Diesen String will ich in ein normales text file schreiben. Jedoch schreibt es mir nur eine Zeile und hängt nichts weiter an. <strong>An was kann das liegen?</strong></p>
<p>Mein Code:</p>
<pre><code class="language-cpp">#include &quot;CDateTime.h&quot;
#include &quot;CSerialPort.h&quot;
#include &quot;CTransitObservator.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

#define BUFSIZE 8192
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])

{

	CDateTime dateTime;
	CTransitObserver transitObserver(&amp;serialPort);
	int comPort = 5;
	int baudRate = 11200;
	string userName;
	string computerName;
	double version = 1.0;	

	//Create LogFile Names
	string logFileTimeStamp = dateTime.DateTime();	
	string errorLogFileName = &quot;errorReport_&quot; + logFileTimeStamp + &quot;.txt&quot;;
	string rawLogFileName	= &quot;raw_&quot;		 + logFileTimeStamp + &quot;.csv&quot;;

	//Create LogFiles
	ofstream oStreamErrorLog, oStreamRawLog;
	oStreamErrorLog.open(errorLogFileName.c_str(), fstream::ate);
	oStreamRawLog.open(rawLogFileName.c_str(), fstream::ate);

	oStreamRawLog &lt;&lt; &quot;\n\nDate:               &quot; &lt;&lt; &quot;Time:             &quot; &lt;&lt; &quot;Data Received:&quot; &lt;&lt; endl;

	while(!kbhit())
	{
		string *receivedData				 = new string;
		unsigned long *numberOfBytesReceived = new unsigned long;
		//Starts Observing
		transitObserver.Observe(receivedData, numberOfBytesReceived);

		//Writes TimeStamp and the Received Data in the raw log File.
		oStreamRawLog &lt;&lt; &quot;\n&quot; &lt;&lt;dateTime.Date() &lt;&lt; &quot;          &quot; &lt;&lt; dateTime.Time() &lt;&lt; &quot;          &quot;  &lt;&lt; *receivedData &lt;&lt; &quot;\r\n&quot;; //funktioniert genau beim 1. Mal

		//Close Log Files
		oStreamErrorLog.close();
		oStreamRawLog.close();

		//Delete Variables
		delete receivedData;
		delete numberOfBytesReceived;
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/277781/file-schreiben-keine-newline</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 20:07:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/277781.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Nov 2010 12:26:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:26:34 GMT]]></title><description><![CDATA[<p>Hi zusammen</p>
<p>Hab wieder einmal eine Frage.</p>
<p>Mein Problem ist, dass ich eine Funktion habe, die mir einen string zurückgibt. Diesen String will ich in ein normales text file schreiben. Jedoch schreibt es mir nur eine Zeile und hängt nichts weiter an. <strong>An was kann das liegen?</strong></p>
<p>Mein Code:</p>
<pre><code class="language-cpp">#include &quot;CDateTime.h&quot;
#include &quot;CSerialPort.h&quot;
#include &quot;CTransitObservator.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

#define BUFSIZE 8192
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])

{

	CDateTime dateTime;
	CTransitObserver transitObserver(&amp;serialPort);
	int comPort = 5;
	int baudRate = 11200;
	string userName;
	string computerName;
	double version = 1.0;	

	//Create LogFile Names
	string logFileTimeStamp = dateTime.DateTime();	
	string errorLogFileName = &quot;errorReport_&quot; + logFileTimeStamp + &quot;.txt&quot;;
	string rawLogFileName	= &quot;raw_&quot;		 + logFileTimeStamp + &quot;.csv&quot;;

	//Create LogFiles
	ofstream oStreamErrorLog, oStreamRawLog;
	oStreamErrorLog.open(errorLogFileName.c_str(), fstream::ate);
	oStreamRawLog.open(rawLogFileName.c_str(), fstream::ate);

	oStreamRawLog &lt;&lt; &quot;\n\nDate:               &quot; &lt;&lt; &quot;Time:             &quot; &lt;&lt; &quot;Data Received:&quot; &lt;&lt; endl;

	while(!kbhit())
	{
		string *receivedData				 = new string;
		unsigned long *numberOfBytesReceived = new unsigned long;
		//Starts Observing
		transitObserver.Observe(receivedData, numberOfBytesReceived);

		//Writes TimeStamp and the Received Data in the raw log File.
		oStreamRawLog &lt;&lt; &quot;\n&quot; &lt;&lt;dateTime.Date() &lt;&lt; &quot;          &quot; &lt;&lt; dateTime.Time() &lt;&lt; &quot;          &quot;  &lt;&lt; *receivedData &lt;&lt; &quot;\r\n&quot;; //funktioniert genau beim 1. Mal

		//Close Log Files
		oStreamErrorLog.close();
		oStreamRawLog.close();

		//Delete Variables
		delete receivedData;
		delete numberOfBytesReceived;
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1985090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985090</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:26:34 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:33:09 GMT]]></title><description><![CDATA[<p>Ob du deine Datei da wohl geschlossen hast und nicht wieder öffnest?</p>
<p>Kommetar zu dem Code: Oh Graus, wie schrecklich. Ich überabeite dies mal eben, bin gleich wieder da.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985092</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:33:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">oStreamRawLog.close();
</code></pre>
<p>Und was soll das denn</p>
<pre><code class="language-cpp">string *receivedData                 = new string;
unsigned long *numberOfBytesReceived = new unsigned long;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1985093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985093</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:33:31 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:37:46 GMT]]></title><description><![CDATA[<p>brotbernd schrieb:</p>
<blockquote>
<pre><code class="language-cpp">oStreamRawLog.close();
</code></pre>
</blockquote>
<p>Ja das war das Problem. Wie SeppJ geagt hat.</p>
<p>brotbernd schrieb:</p>
<blockquote>
<p>Und was soll das denn</p>
<pre><code class="language-cpp">string *receivedData                 = new string;
unsigned long *numberOfBytesReceived = new unsigned long;
</code></pre>
</blockquote>
<p>Ich weiss nicht. Was stimmt denn daran nicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985095</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:40:35 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &quot;CDateTime.h&quot;
#include &quot;CSerialPort.h&quot;
#include &quot;CTransitObservator.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt; 
//#include &lt;conio.h&gt;  // Wozu?

const unsigned BUFSIZE=8192;
//-----------------------------------------------------------------------------
int main() // Wozu argc und argv?

{

    CDateTime dateTime;
    CTransitObserver transitObserver(&amp;serialPort);
    int comPort = 5;        // Konstanten? Falls ja, dann mach welche daraus
    int baudRate = 11200;
    string userName;
    string computerName;
    double version = 1.0;   

    //Create LogFiles
    ofstream oStreamErrorLog(errorLogFileName.c_str(), fstream::ate);
    ofstream oStreamRawLog(rawLogFileName.c_str(), fstream::ate);

    oStreamRawLog &lt;&lt; &quot;\n\nDate:               &quot; &lt;&lt; &quot;Time:             &quot; &lt;&lt; &quot;Data Received:&quot; &lt;&lt; endl;

    while(!kbhit())
    {
        string receivedData;
        unsigned long numberOfBytesReceived;
        //Starts Observing
        transitObserver.Observe(&amp;receivedData, &amp;numberOfBytesReceived);
        // Bist du sicher, dass Observe einen String* braucht? Das ist ist extrem ungewöhnlich. Selbst geschrieben?

        //Writes TimeStamp and the Received Data in the raw log File.
        oStreamRawLog &lt;&lt; &quot;\n&quot; &lt;&lt;dateTime.Date() &lt;&lt; &quot;          &quot; &lt;&lt; dateTime.Time() &lt;&lt; &quot;          &quot;  &lt;&lt; *receivedData &lt;&lt; &quot;\r\n&quot;; 
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1985097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985097</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:40:35 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:42:12 GMT]]></title><description><![CDATA[<p>TTS schrieb:</p>
<blockquote>
<p>Ich weiss nicht. Was stimmt denn daran nicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Erklärs mir. Löscht die <code>transitObserver.Observe</code> und erzeugt neu Instanzen oder wozu ist das gut. Wahrscheinlich für goarnix. von daher</p>
<pre><code class="language-cpp">string receivedData;
unsigned long numberOfBytesReceived = 0;
//Starts Observing
transitObserver.Observe(&amp;receivedData, &amp;numberOfBytesReceived);
</code></pre>
<p>Noch schöner wäre, wenn die Methdoe enfach nur den string zurück gibt. numberOfBytesReceived ist halt result.size();.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985100</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:42:12 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:49:28 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">//#include &lt;conio.h&gt;  // Wozu?
</code></pre>
</blockquote>
<p>Hierfür:</p>
<pre><code class="language-cpp">while(!kbhit())
{
}
</code></pre>
<p>SeppJ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int main() // Wozu argc und argv?
</code></pre>
</blockquote>
<p>Damit das Programm mit Parametern gestartet werden kann. z.B. -com 5 -baud 9600 ...</p>
<p>SeppJ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int comPort = 5;        // Konstanten? Falls ja, dann mach welche daraus
</code></pre>
</blockquote>
<p>Momentan ja, heute Abend nicht mehr. Bis dann sollte der ComPort als Parameter gesetzt werden können.</p>
<p>SeppJ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">transitObserver.Observe(&amp;receivedData, &amp;numberOfBytesReceived);
// Bist du sicher, dass Observe einen String* braucht? Das ist ist extrem ungewöhnlich. Selbst geschrieben?
</code></pre>
</blockquote>
<p>Ja die Funktion ist selbst geschrieben. Sie liesst Daten über den ComPort ein.</p>
<p>Danke für deine Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985102</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:49:28 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 12:52:54 GMT]]></title><description><![CDATA[<p>brotbernd schrieb:</p>
<blockquote>
<p>Erklärs mir. Löscht die <code>transitObserver.Observe</code> und erzeugt neu Instanzen oder wozu ist das gut. Wahrscheinlich für goarnix. von daher</p>
</blockquote>
<p>Nee. Oben wird Speicher für die beiden Variablen alloziert. Und am ende der Schleiffe mit delete wieder freigegeben.</p>
<p>brotbernd schrieb:</p>
<blockquote>
<pre><code class="language-cpp">string receivedData;
unsigned long numberOfBytesReceived = 0;
//Starts Observing
transitObserver.Observe(&amp;receivedData, &amp;numberOfBytesReceived);
</code></pre>
<p>Noch schöner wäre, wenn die Methdoe enfach nur den string zurück gibt. numberOfBytesReceived ist halt result.size();.</p>
</blockquote>
<p>Danke auf das mit result.size() bin ich nicht gekommen. Aber das ist sowieso nur für Testzwecke später benötige ich die Anzahl empfangener Bytes nicht mehr.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985103</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Wed, 24 Nov 2010 12:52:54 GMT</pubDate></item><item><title><![CDATA[Reply to File schreiben, keine newline on Wed, 24 Nov 2010 13:10:06 GMT]]></title><description><![CDATA[<p>TTS schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">transitObserver.Observe(&amp;receivedData, &amp;numberOfBytesReceived);
// Bist du sicher, dass Observe einen String* braucht? Das ist ist extrem ungewöhnlich. Selbst geschrieben?
</code></pre>
</blockquote>
<p>Ja die Funktion ist selbst geschrieben. Sie liesst Daten über den ComPort ein.</p>
</blockquote>
<p>Informier dich mal, was eine Referenz ist. Ganz wichtiges Thema.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1985108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1985108</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 24 Nov 2010 13:10:06 GMT</pubDate></item></channel></rss>