<?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[getline() special...]]></title><description><![CDATA[<p>Hey,</p>
<p>I found something special in the getline() function, I don't understand.</p>
<p>If I use the getline function in case of an Excel-sheet or an image - to get the image-data - the getline function breakes after a NULL termination ( \0 )</p>
<p>fstream oFile_e;</p>
<p>oFile_e.open(&quot;BAB.xls&quot;,ios::in);</p>
<p>oFile_e.getline(chTest, 100,'\n');</p>
<p>BAB.xls containes the \0 from position 9 to 12</p>
<p>chTest is after the getline function only filled up to position 9 ( after the first \0 )</p>
<p>--&gt; no problem with the ios::binary mode. With this mode it's possible to read the whole data.</p>
<p>But if I write out some chars in a file and some of them are \0, I can read the whole data WITHOUT the ios::binary mode.</p>
<p>Do you understand that phenomenon?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174366/getline-special</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 17:29:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174366.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Feb 2007 08:05:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to getline() special... on Mon, 26 Feb 2007 08:05:38 GMT]]></title><description><![CDATA[<p>Hey,</p>
<p>I found something special in the getline() function, I don't understand.</p>
<p>If I use the getline function in case of an Excel-sheet or an image - to get the image-data - the getline function breakes after a NULL termination ( \0 )</p>
<p>fstream oFile_e;</p>
<p>oFile_e.open(&quot;BAB.xls&quot;,ios::in);</p>
<p>oFile_e.getline(chTest, 100,'\n');</p>
<p>BAB.xls containes the \0 from position 9 to 12</p>
<p>chTest is after the getline function only filled up to position 9 ( after the first \0 )</p>
<p>--&gt; no problem with the ios::binary mode. With this mode it's possible to read the whole data.</p>
<p>But if I write out some chars in a file and some of them are \0, I can read the whole data WITHOUT the ios::binary mode.</p>
<p>Do you understand that phenomenon?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1235578</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1235578</guid><dc:creator><![CDATA[FightingWolf]]></dc:creator><pubDate>Mon, 26 Feb 2007 08:05:38 GMT</pubDate></item><item><title><![CDATA[Reply to getline() special... on Mon, 26 Feb 2007 08:15:35 GMT]]></title><description><![CDATA[<p>getline() still reads the whole line of your file, but you use it as a C-string (char-array) afterwards. And from C's point of view, the character '\0' marks the end of a string, so any access through C functions would only result in the part before the first '\0' mark.</p>
<p>The best solution would be using the class std::string an the global function getline() instead of the istream member. Or you could use the method 'gcount()' to find out the real length of the read string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1235582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1235582</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 26 Feb 2007 08:15:35 GMT</pubDate></item><item><title><![CDATA[Reply to getline() special... on Mon, 26 Feb 2007 13:27:21 GMT]]></title><description><![CDATA[<p>thx for the answer but I think you don't understand what I mean. If i use the ios::binary mode in the getline function it works, too. But I don't understand why this funcion breakes ( stops ) reading when I read out image data, and an other time it continues ( when I write the data myself into an file with \0 ).</p>
<p>for example:</p>
<p>the image data: abcde\0\0\0\0cdf\0\0a<br />
the data I wrote into a file: abc\0\0\0a</p>
<p>now I read out both data with the same function and the same values / attributes.</p>
<p>So why fills the getline function my array compleately to the last char ( a ) at my own data and not only to the first \0 mark like in the image data?</p>
<p>Both files containes \0. One time I have an return of the function ( own data in an array: abc\0\0\0a ), one time not ( Image data in an array: abcde\0\0\0\0cdf\0\0a ).</p>
<p>So look... I don't have any problems to read out any data from an file, but im interested in this phenomenon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1235729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1235729</guid><dc:creator><![CDATA[FightingWolf]]></dc:creator><pubDate>Mon, 26 Feb 2007 13:27:21 GMT</pubDate></item></channel></rss>