<?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[fstream nimmt den Rückgabewert von readline nicht an (Linux)]]></title><description><![CDATA[<p>Hallo ich bin neu hier im Forum und auch bei C++.<br />
Was ich bis heute so versucht habe war eine kleine Konsolenanwendung welche lediglich eine Datei öfnnet und wieder Zeilenweise ausgibt wobei die Ausgabe auf Zeilen beschränkt ist welche nur Zahlen enthalten. Dies war nicht so schwierig .. leider hat es mich genervt immer den kompletten Dateinamen anzugeben ... also habe ich mit mit der readline Lib angfreundet. Das hat funktioniert aber irgendwie bekomme ich nun fstream nicht mehr dazu die datei zu öfnnen deren Dateinamen ich über readline() einglesen hab ... undas obwohl ich mich an char* sowohl für readline und auch fstream gehalten hab ... vielleicht könnt ihr mir ein wenig helfem?</p>
<pre><code class="language-cpp">/*
This simple program shows how to read a file whose 
filename is specified by the user and autocompleted
and how each line of the file which contains solely numbers is printed on the screen
*/

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;
#include &lt;readline/readline.h&gt;
#include &lt;readline/history.h&gt;

char* line_read; 
void lineOutput( std::fstream&amp; stream ); //the function which displays each line on the screen
char* rl_gets();

int main() {

std::cout &lt;&lt; &quot;Please enter a filename: \n&quot;;
std::fstream inputfile;
const char* filename = rl_gets(); 
inputfile.open(filename, std::ios::in); 
 if( !(inputfile) ){
   std::cerr &lt;&lt; &quot;ERROR: Cannot open file!&quot; &lt;&lt;&quot;\n&quot;;
 }
lineOutput(inputfile); //line by line output function
return 0;

}

void lineOutput (std::fstream&amp; stream){
  char buffer[512];
  int cnt=1;
  while( stream.getline(buffer, sizeof(buffer)) ){
    if( stream.fail() ){
      std::cout &lt;&lt; &quot;Unexpected ERROR ! ! !&quot; &lt;&lt; std::endl;
      break;
    }
    if(isdigit(buffer[0])){ // this conditions tests if the char contains numbers
      std::cout &lt;&lt; cnt++ &lt;&lt; &quot; : &quot; &lt;&lt; buffer &lt;&lt; std::endl;
    }
  }
}

char* rl_gets ()
{
  line_read = readline (&quot;&quot;);
  return (line_read);
}
</code></pre>
<p>Zeile 24 hätte ich mir sparen können aber ich wollte auf nummer sicher gehen. Das Program läuft aber fstream kann die Datei nicht öffnen ... habe auch mehrere verschiedene Dateinen (mit und ohne Dateiendung) ausprobiert.<br />
Ich bin ein wenig ratlos.<br />
Grüße + Vielen Dank!<br />
glycylalanin :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297251/fstream-nimmt-den-rückgabewert-von-readline-nicht-an-linux</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 13:40:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297251.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Dec 2011 09:55:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 09:55:22 GMT]]></title><description><![CDATA[<p>Hallo ich bin neu hier im Forum und auch bei C++.<br />
Was ich bis heute so versucht habe war eine kleine Konsolenanwendung welche lediglich eine Datei öfnnet und wieder Zeilenweise ausgibt wobei die Ausgabe auf Zeilen beschränkt ist welche nur Zahlen enthalten. Dies war nicht so schwierig .. leider hat es mich genervt immer den kompletten Dateinamen anzugeben ... also habe ich mit mit der readline Lib angfreundet. Das hat funktioniert aber irgendwie bekomme ich nun fstream nicht mehr dazu die datei zu öfnnen deren Dateinamen ich über readline() einglesen hab ... undas obwohl ich mich an char* sowohl für readline und auch fstream gehalten hab ... vielleicht könnt ihr mir ein wenig helfem?</p>
<pre><code class="language-cpp">/*
This simple program shows how to read a file whose 
filename is specified by the user and autocompleted
and how each line of the file which contains solely numbers is printed on the screen
*/

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;
#include &lt;readline/readline.h&gt;
#include &lt;readline/history.h&gt;

char* line_read; 
void lineOutput( std::fstream&amp; stream ); //the function which displays each line on the screen
char* rl_gets();

int main() {

std::cout &lt;&lt; &quot;Please enter a filename: \n&quot;;
std::fstream inputfile;
const char* filename = rl_gets(); 
inputfile.open(filename, std::ios::in); 
 if( !(inputfile) ){
   std::cerr &lt;&lt; &quot;ERROR: Cannot open file!&quot; &lt;&lt;&quot;\n&quot;;
 }
lineOutput(inputfile); //line by line output function
return 0;

}

void lineOutput (std::fstream&amp; stream){
  char buffer[512];
  int cnt=1;
  while( stream.getline(buffer, sizeof(buffer)) ){
    if( stream.fail() ){
      std::cout &lt;&lt; &quot;Unexpected ERROR ! ! !&quot; &lt;&lt; std::endl;
      break;
    }
    if(isdigit(buffer[0])){ // this conditions tests if the char contains numbers
      std::cout &lt;&lt; cnt++ &lt;&lt; &quot; : &quot; &lt;&lt; buffer &lt;&lt; std::endl;
    }
  }
}

char* rl_gets ()
{
  line_read = readline (&quot;&quot;);
  return (line_read);
}
</code></pre>
<p>Zeile 24 hätte ich mir sparen können aber ich wollte auf nummer sicher gehen. Das Program läuft aber fstream kann die Datei nicht öffnen ... habe auch mehrere verschiedene Dateinen (mit und ohne Dateiendung) ausprobiert.<br />
Ich bin ein wenig ratlos.<br />
Grüße + Vielen Dank!<br />
glycylalanin :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160058</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160058</guid><dc:creator><![CDATA[glycylalanin]]></dc:creator><pubDate>Thu, 22 Dec 2011 09:55:22 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 10:24:21 GMT]]></title><description><![CDATA[<p>Funktioniert bei mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160063</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 22 Dec 2011 10:24:21 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 10:31:43 GMT]]></title><description><![CDATA[<p>Ahhhh ....<br />
bei mir funktioniert es auch aber NUR wenn ich die Datei eintippe ...nicht wenn ich die Autocompletionfunktion nutze (also ein-zwei Buchstaben dann TAB dann ENTER). Hmmm .... d.h. das das was von readline zurückgegeben wird irgendwie zwar gleich aussieht wenn man sichs mit cout ausgeben lässt aber nicht das gleiche ist wie wenn man's eintippt?</p>
<p>Grüße und Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160064</guid><dc:creator><![CDATA[glycylalanin]]></dc:creator><pubDate>Thu, 22 Dec 2011 10:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 10:39:37 GMT]]></title><description><![CDATA[<p>ich habe gerade entdeckt, dass wenn man sich mit readline + TAB einen Dateinamen versvollständigen lässt am Ende ein Leerzeichen oder gar der TAB selbst angehängt wird, wenn man aber das ganze nur eintippt geschieht das natürlich nicht. Aber wie kann ich verhindern das der TAB als Zeichen miteingelesen wird?<br />
Grüße,<br />
glycylalanin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160066</guid><dc:creator><![CDATA[glycylalanin]]></dc:creator><pubDate>Thu, 22 Dec 2011 10:39:37 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 10:40:31 GMT]]></title><description><![CDATA[<p>glycylalanin schrieb:</p>
<blockquote>
<p>Ahhhh ....<br />
bei mir funktioniert es auch aber NUR wenn ich die Datei eintippe ...nicht wenn ich die Autocompletionfunktion nutze (also ein-zwei Buchstaben dann TAB dann ENTER). Hmmm .... d.h. das das was von readline zurückgegeben wird irgendwie zwar gleich aussieht wenn man sichs mit cout ausgeben lässt aber nicht das gleiche ist wie wenn man's eintippt?</p>
<p>Grüße und Danke!</p>
</blockquote>
<p>Kann ich nicht nachvollziehen. Bist du sicher, dass der vervollständigte Name eindeutig auf eine Datei verweist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160067</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160067</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 22 Dec 2011 10:40:31 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 10:52:41 GMT]]></title><description><![CDATA[<p>ja ... ich hab mir in Zeile 11 und 12 (siehe unten) die beiden variablen nochmal ausgeben lassen. Wenn Du also eine Datei bsp. test.txt so eingibst te+TAB+ENTER dann befindet sich Platz zwischen dem ausgegebenen Dateinamen und dem senkrechten Strich. Der Platz verscwindet wenn du gleich test.txt+ENTER eingibst. Dann findet fstream die Datei auch.</p>
<pre><code class="language-cpp">int main() {

std::cout &lt;&lt; &quot;Please enter a filename: \n&quot;;
std::fstream inputfile;
rl_gets();
const char *filename = line_read; 
inputfile.open(filename, std::ios::in); 
 if( !(inputfile) ){
   std::cerr &lt;&lt; &quot;ERROR: Cannot open &quot; &lt;&lt;filename &lt;&lt;&quot;!&quot; &lt;&lt;&quot;\n&quot;;
 }
 std::cerr&lt;&lt;line_read &lt;&lt;&quot;|&quot; &lt;&lt;&quot;\n&quot;;
 std::cerr&lt;&lt;filename &lt;&lt;&quot;|&quot; &lt;&lt;&quot;\n&quot;;
lineOutput(inputfile); //line by line output function
return 0;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2160071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160071</guid><dc:creator><![CDATA[glycylalanin]]></dc:creator><pubDate>Thu, 22 Dec 2011 10:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 11:11:19 GMT]]></title><description><![CDATA[<p>Ok, <strong>das</strong> kann ich nachvollziehen. Kurzes Googlen ergibt, dass du wohl <code>rl_completion_suppress_append</code> setzen musst. Wie das genau geht musst du selbst heraus finden, ich lese nicht die gesamte Anleitung für dich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160077</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 22 Dec 2011 11:11:19 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 11:13:40 GMT]]></title><description><![CDATA[<p>würd ich auch nicht verlangen ...VIELEN DANK! <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/2160079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160079</guid><dc:creator><![CDATA[glycylalanin]]></dc:creator><pubDate>Thu, 22 Dec 2011 11:13:40 GMT</pubDate></item><item><title><![CDATA[Reply to fstream nimmt den Rückgabewert von readline nicht an (Linux) on Thu, 22 Dec 2011 12:12:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">while( stream.getline(buffer, sizeof(buffer)) ){
    if( stream.fail() ){
      std::cout &lt;&lt; &quot;Unexpected ERROR ! ! !&quot; &lt;&lt; std::endl;
      break;
    } 

...
</code></pre>
<p>Auf fail zu prüfen ist unsinnig da der Punkt nie erreicht wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2160094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2160094</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Thu, 22 Dec 2011 12:12:10 GMT</pubDate></item></channel></rss>