<?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[gesamtes file einlesen und in liste speichern]]></title><description><![CDATA[<p>Ich möchte ein 40 MB grosses file einlesen und in einer Liste abspeichern.<br />
Hier mein Versuch, das einlesen in stream ist falsch. Und das Speichern in die Liste funktioniert nicht.</p>
<pre><code class="language-cpp">readin (const char* testfile ) {

	int i,j;

	fileisopen=false;
	outfileisopen=false;
	FILE * file = new File( testfile );
	stream= new Stream( file );

	fileisopen=file-&gt;open( ReadOnly );

	numlines=0;
	if ( fileisopen) {

			stream-&gt;device()-&gt;reset();
			while ( !stream-&gt;atEnd() ) {
				list.append(stream-&gt;readLine()); 			}

			numlines=linelist.count();
			printf(&quot;%d lines read\n&quot;,numlines);
	}

	file-&gt;close();
	it = linelist.begin();
</code></pre>
<p>bin für jede Hilfe dankbar..</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/177202/gesamtes-file-einlesen-und-in-liste-speichern</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 23:26:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/177202.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Mar 2007 08:17:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 08:17:54 GMT]]></title><description><![CDATA[<p>Ich möchte ein 40 MB grosses file einlesen und in einer Liste abspeichern.<br />
Hier mein Versuch, das einlesen in stream ist falsch. Und das Speichern in die Liste funktioniert nicht.</p>
<pre><code class="language-cpp">readin (const char* testfile ) {

	int i,j;

	fileisopen=false;
	outfileisopen=false;
	FILE * file = new File( testfile );
	stream= new Stream( file );

	fileisopen=file-&gt;open( ReadOnly );

	numlines=0;
	if ( fileisopen) {

			stream-&gt;device()-&gt;reset();
			while ( !stream-&gt;atEnd() ) {
				list.append(stream-&gt;readLine()); 			}

			numlines=linelist.count();
			printf(&quot;%d lines read\n&quot;,numlines);
	}

	file-&gt;close();
	it = linelist.begin();
</code></pre>
<p>bin für jede Hilfe dankbar..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255138</guid><dc:creator><![CDATA[*lt*---*gt*]]></dc:creator><pubDate>Thu, 29 Mar 2007 08:17:54 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 08:27:35 GMT]]></title><description><![CDATA[<p>Was für eine API ist das? Unter C++ funktioniert das anders. Außerdem sind da auch Fehler drin.</p>
<pre><code class="language-cpp">void readin(string const&amp; filename)
{
    ifstream ifs(filename.c_str());

    if (not ifs) return;

    string line;
    while (getline(ifs, line))
        list.push_back(line);

    it = list.begin();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1255141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255141</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Thu, 29 Mar 2007 08:27:35 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 08:28:42 GMT]]></title><description><![CDATA[<p>Benutze einen Vector, der reicht völlig.</p>
<pre><code class="language-cpp">vectorname.push_back(datei.getline(...));
</code></pre>
<p>und zugriff dann normal per index:<br />
vectorname[zeile];</p>
<p>Bedenke, das ein Vector sich nur soweit erweitert, wie Arbeitsspeicher zur Verfuegung steht. Solltest du keine 40MB mehr frei haben, funktioniert deine logik nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255142</guid><dc:creator><![CDATA[kjvsdkfsdkf]]></dc:creator><pubDate>Thu, 29 Mar 2007 08:28:42 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 08:31:29 GMT]]></title><description><![CDATA[<p>Wenn du unbedingt mit FILE's arbeiten willst, musst du auch die C-IO-Funktionen (fopen, fgets,...) verwenden. Aber besser ist es, du verwendest fstreams.<br />
(und schaust dir ein Tutorial an, wie man damit umgehen kann)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255143</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 29 Mar 2007 08:31:29 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 11:45:56 GMT]]></title><description><![CDATA[<p>Erstmal vielen Dank. Ich hatte eine Bibliotek mit c++ Funktionen vermischt.</p>
<p>Leider hane ich immer noch Probleme das File in den Vektor einzulesen.<br />
Also ich habe jetzt zur Vereinfachung alles in main:</p>
<pre><code class="language-cpp">#include&lt;cstdlib&gt;
#include&lt;fstream&gt;
#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;string&gt;
using namespace std;

int main() {

vector &lt;string&gt; v1;
int x,y;

   //ifstream ifs(filename.c_str()); //öffne angegebenes File

    ifstream quelle;
    quelle.open(&quot;test.PC&quot;); //ist ascii datei
    if (!quelle) {
        cerr &lt;&lt; &quot;Datei kann nicht geöffnet werden!\n&quot;;
        exit(-1);
    }
    string line; 
    while (!quelle.eof()) {
       v1.push_back(quelle.getline(line, sizeof(line)));
    /*hier error C2664: 'class std::basic_istream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp;__thiscall std::basic_istream&lt;char,struct std::char_traits&lt;char&gt; &gt;::getline(char *,int)' : Konvertierung des Parameters 1 
von 'class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;' in 'char *' nicht moeglich*/

    f.close();

    quelle.close();  

    cin.get();   // Eingabe von RETURN beendet das Programm
}   // automatisches {\tt close()}
</code></pre>
<p>desweiteren möchte ich nicht alles aus dem file auslesen(ist 40 mb gross), sondern nur bestimmte Sequenzen.</p>
<p>das file ist so aufgebaut, dass am Anfang jeder Zeile zu erkennen ist zu welcher Kategorie und Unterkategorie die Zeileninhalte gehören.<br />
z.B. SEURPNLDZALD, brauche ich das 4.Zeichen(bei 0 angefangen) als Indikator welche Oberkategorie und das 12.Zeichen als Indikator welche Unterkategorie.<br />
mein Versuch:</p>
<pre><code class="language-cpp">int i,j;
int sec;
int subsec;
	//*** initialize extract  *********
	for(i=0;i&lt;=7;i++){            //Kategorie
		for(j=0;j&lt;=15;j++){  //Unterkategorie
			string extract[i][j]=0; //hier Fehler weil keine Konstanten.  ?? ich möchte das array dynamisch befüllen. Bzw. hier mit 0 initilisieren

			//********** which section**************

				if(quelle.seekg(4) == 'A')	{
						sec=1;	
				}
				else if(quelle.seekg(4)=='D') sec=2;
				else ifquelle.seekg(4)=='E') sec=2;
				//usw.
				else{
					it++;
					return(1);
				}

			//******** section wanted?****************

				w=0;
				for(i=0;i&lt;15;i++){

					w=w+extract[sec-1][i];
				}

				if(w==0){
					it++;
					return(1);
				}

			//********	which subsection **************+	

				switch (sec){

					case 1://brauche ich nicht

						break;

					case 2: //brauche ich											
						if((quelle.seekg(12).isSpace()) subsec;=0;				
						else if(quelle.seekg(12)=='B') subsec=1;
						else{
							it++; 
							return(1);
						}
</code></pre>
<p>Ist das von der Logik her richtig. Nun ja, ich hoffe meine Beschreibung ist überhaupt zu verstehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255256</guid><dc:creator><![CDATA[*lt*---*gt*]]></dc:creator><pubDate>Thu, 29 Mar 2007 11:45:56 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Thu, 29 Mar 2007 11:52:54 GMT]]></title><description><![CDATA[<p>Erstmal: getline() liefert nicht den gelesenen String zurück, sondern den Stream(status).</p>
<p>Zweitens: Die istream-Methode getline() arbeitet auf char-Arrays, besser ist die globale Funktion getline() (die verwendet std::string).</p>
<p>Damit klappt das Einlesen eher so:</p>
<pre><code class="language-cpp">ifstream quelle(&quot;test.PC&quot;);
string zeile;
while(getline(quelle,zeile))
{
  vl.push_back(zeile);
  //wenn du die Eingabezeilen auswerten willst, ist hier vermutlich der richtige Platz dafür
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1255259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255259</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 29 Mar 2007 11:52:54 GMT</pubDate></item><item><title><![CDATA[Reply to gesamtes file einlesen und in liste speichern on Fri, 30 Mar 2007 07:28:34 GMT]]></title><description><![CDATA[<p>Danke!<br />
Einlesen funkt nun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255775</guid><dc:creator><![CDATA[*lt*---*gt*]]></dc:creator><pubDate>Fri, 30 Mar 2007 07:28:34 GMT</pubDate></item></channel></rss>