<?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[Methode zum einlesen und trennen von dateiinhalten gut?]]></title><description><![CDATA[<p>hallo,</p>
<p>problemstellung:</p>
<p>ich muss eine datei einlesen welche mehrere &quot;info&quot; blöcke enthält...</p>
<p>im programm kann man dann zwischen den infoblöcken umschalten...</p>
<p>meine idee daher:</p>
<p>für jeden infoblock eine Stringlist, damit beim umschalten nur in eine andere list geswitched wird, und nicht andauernd neu gesucht usw werden muss...</p>
<p>vorgehensweise (gedacht)<br />
1 file in List einlesen<br />
2 Blöcke (beginnen immer mit 512) suchen<br />
3 Anfans und Endzeile zwischenspeichern<br />
4 Blöcke aus List in seperate lists kopieren</p>
<p>dazeiinhalt:</p>
<pre><code>512 33
51332423480932840923483204
51423424234324234565565466
512 43443
51323423432423423432
512543242
513234234324
5145435345345435543543534543543
512 34
51332423480932840923483204
51423424234324234565565466
512 43443
51323423432423423432
512543242
513234234324
5145435345345435543543534543500000
</code></pre>
<p>.h</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#ifndef offnen_splittemH
#define offnen_splittemH
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
#include &lt;Dialogs.hpp&gt;
#include &lt;Menus.hpp&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
        TOpenDialog *OpenDialog1;
        TMainMenu *MainMenu1;
        TMenuItem *Datei1;
        TMenuItem *ffnen1;
        TMemo *Memo1;
        void __fastcall ffnen1Click(TObject *Sender);
private:	// Anwender-Deklarationen
public:		// Anwender-Deklarationen
        TStringList* VDAList;
        //std::pair&lt;int,int&gt;* startStopArea;
        std::vector&lt;std::pair&lt;int,int&gt; &gt; startStopVector;
        int areaCounter;
        __fastcall TForm1(TComponent* Owner);
        std::vector&lt;int&gt; startStopPositions;
        void __fastcall FindAreas();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p>.cpp</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;offnen_splittem.h&quot;
#include &lt;vector&gt;
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ffnen1Click(TObject *Sender)
{
if(OpenDialog1-&gt;Execute())
 {
   //free memory not to seg_fault exception
   delete VDAList;
   VDAList = 0;

   //allocate new memory for list
   VDAList = new TStringList();
   VDAList-&gt;LoadFromFile(OpenDialog1-&gt;FileName);

   //set all new
   startStopPositions.clear();
   areaCounter = 0;
   //delete[] startStopArea;

   //Now get the area koords
   FindAreas();

   //Debugoutput
   Memo1-&gt;Lines-&gt;Add(&quot;Anzahl Zeilen in Datei: &quot; + String(VDAList-&gt;Count));
   Memo1-&gt;Lines-&gt;Add(&quot;Bereiche: &quot; + String(areaCounter));

 }
}
//---------------------------------------------------------------------------

//fills startStopArea and areaCounter
//that you are able to seperate it later
void __fastcall TForm1::FindAreas()
{
  int start, stop;      //start und stop dea areals
  //search for areas (512 starts a area)
  int searchLen = VDAList-&gt;Count;
  for(int i = 0;i &lt; searchLen;++i)
     {
       if(VDAList-&gt;Strings[i].SubString(0,3)==&quot;512&quot;)
          {
            areaCounter++;
            startStopPositions.push_back(i);
          }
     }
     //alloc memory for pairs which includes the start and stop positions of an area
     //startStopArea = new pair&lt;int,int&gt;[areaCounter];

     Memo1-&gt;Lines-&gt;Add(&quot;Positionen im Vector: &quot; + String(startStopPositions.size()));

     //------------------------------------------------------
     for(unsigned int i=0;i&lt;startStopPositions.size();++i)
      Memo1-&gt;Lines-&gt;Add(String(startStopPositions.at(i)));
     //------------------------------------------------------

     //Check if all vector-positions the same as the count of areas
     if(areaCounter!=startStopPositions.size())
        ShowMessage(&quot;Fehler bei Synchronisation&quot;);

      //fill the pairs with koords
      for(int i = 0;i &lt; areaCounter; ++i)
         {
          //-----------manual methode--------------------
          /*startStopArea[i].first = startStopPositions.at(i);
          //if
          if(i + 1 &gt;= areaCounter)
             startStopArea[i].second = searchLen;
          else
             startStopArea[i].second = startStopPositions.at(i+1);

          if(i!=areaCounter-1)
            startStopArea[i].second = startStopArea[i].second -1 ;           */
          //----------------------------------------------------

          //automatic vector works better
          start = startStopPositions.at(i);

          //end reached??
          if(i+1 &gt;= areaCounter)
             stop = searchLen;
          else
             stop = startStopPositions.at(i+1);

          //end of one area is not the same like the beginning of the next
          if(i!=areaCounter-1)
             --stop;
          /
          /fill up vector
          startStopVector.push_back(make_pair(start,stop));

          //debugoutput
          Memo1-&gt;Lines-&gt;Add(&quot;Pair #&quot; + String(i) + &quot;: Start: &quot; + String(startStopVector[i].first)+ &quot; Stop: &quot; + String(startStopVector[i].second));
         }

}
</code></pre>
<p>ist die idee und das vorgehen so gut?<br />
oder gibt es bedeutend bessere möglichkeiten?<br />
und wie sieht meine umsetzung bis jetzt aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/159956/methode-zum-einlesen-und-trennen-von-dateiinhalten-gut</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 03:38:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/159956.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Sep 2006 12:51:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Methode zum einlesen und trennen von dateiinhalten gut? on Wed, 20 Sep 2006 12:51:07 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>problemstellung:</p>
<p>ich muss eine datei einlesen welche mehrere &quot;info&quot; blöcke enthält...</p>
<p>im programm kann man dann zwischen den infoblöcken umschalten...</p>
<p>meine idee daher:</p>
<p>für jeden infoblock eine Stringlist, damit beim umschalten nur in eine andere list geswitched wird, und nicht andauernd neu gesucht usw werden muss...</p>
<p>vorgehensweise (gedacht)<br />
1 file in List einlesen<br />
2 Blöcke (beginnen immer mit 512) suchen<br />
3 Anfans und Endzeile zwischenspeichern<br />
4 Blöcke aus List in seperate lists kopieren</p>
<p>dazeiinhalt:</p>
<pre><code>512 33
51332423480932840923483204
51423424234324234565565466
512 43443
51323423432423423432
512543242
513234234324
5145435345345435543543534543543
512 34
51332423480932840923483204
51423424234324234565565466
512 43443
51323423432423423432
512543242
513234234324
5145435345345435543543534543500000
</code></pre>
<p>.h</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#ifndef offnen_splittemH
#define offnen_splittemH
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
#include &lt;Dialogs.hpp&gt;
#include &lt;Menus.hpp&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
        TOpenDialog *OpenDialog1;
        TMainMenu *MainMenu1;
        TMenuItem *Datei1;
        TMenuItem *ffnen1;
        TMemo *Memo1;
        void __fastcall ffnen1Click(TObject *Sender);
private:	// Anwender-Deklarationen
public:		// Anwender-Deklarationen
        TStringList* VDAList;
        //std::pair&lt;int,int&gt;* startStopArea;
        std::vector&lt;std::pair&lt;int,int&gt; &gt; startStopVector;
        int areaCounter;
        __fastcall TForm1(TComponent* Owner);
        std::vector&lt;int&gt; startStopPositions;
        void __fastcall FindAreas();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p>.cpp</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;offnen_splittem.h&quot;
#include &lt;vector&gt;
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ffnen1Click(TObject *Sender)
{
if(OpenDialog1-&gt;Execute())
 {
   //free memory not to seg_fault exception
   delete VDAList;
   VDAList = 0;

   //allocate new memory for list
   VDAList = new TStringList();
   VDAList-&gt;LoadFromFile(OpenDialog1-&gt;FileName);

   //set all new
   startStopPositions.clear();
   areaCounter = 0;
   //delete[] startStopArea;

   //Now get the area koords
   FindAreas();

   //Debugoutput
   Memo1-&gt;Lines-&gt;Add(&quot;Anzahl Zeilen in Datei: &quot; + String(VDAList-&gt;Count));
   Memo1-&gt;Lines-&gt;Add(&quot;Bereiche: &quot; + String(areaCounter));

 }
}
//---------------------------------------------------------------------------

//fills startStopArea and areaCounter
//that you are able to seperate it later
void __fastcall TForm1::FindAreas()
{
  int start, stop;      //start und stop dea areals
  //search for areas (512 starts a area)
  int searchLen = VDAList-&gt;Count;
  for(int i = 0;i &lt; searchLen;++i)
     {
       if(VDAList-&gt;Strings[i].SubString(0,3)==&quot;512&quot;)
          {
            areaCounter++;
            startStopPositions.push_back(i);
          }
     }
     //alloc memory for pairs which includes the start and stop positions of an area
     //startStopArea = new pair&lt;int,int&gt;[areaCounter];

     Memo1-&gt;Lines-&gt;Add(&quot;Positionen im Vector: &quot; + String(startStopPositions.size()));

     //------------------------------------------------------
     for(unsigned int i=0;i&lt;startStopPositions.size();++i)
      Memo1-&gt;Lines-&gt;Add(String(startStopPositions.at(i)));
     //------------------------------------------------------

     //Check if all vector-positions the same as the count of areas
     if(areaCounter!=startStopPositions.size())
        ShowMessage(&quot;Fehler bei Synchronisation&quot;);

      //fill the pairs with koords
      for(int i = 0;i &lt; areaCounter; ++i)
         {
          //-----------manual methode--------------------
          /*startStopArea[i].first = startStopPositions.at(i);
          //if
          if(i + 1 &gt;= areaCounter)
             startStopArea[i].second = searchLen;
          else
             startStopArea[i].second = startStopPositions.at(i+1);

          if(i!=areaCounter-1)
            startStopArea[i].second = startStopArea[i].second -1 ;           */
          //----------------------------------------------------

          //automatic vector works better
          start = startStopPositions.at(i);

          //end reached??
          if(i+1 &gt;= areaCounter)
             stop = searchLen;
          else
             stop = startStopPositions.at(i+1);

          //end of one area is not the same like the beginning of the next
          if(i!=areaCounter-1)
             --stop;
          /
          /fill up vector
          startStopVector.push_back(make_pair(start,stop));

          //debugoutput
          Memo1-&gt;Lines-&gt;Add(&quot;Pair #&quot; + String(i) + &quot;: Start: &quot; + String(startStopVector[i].first)+ &quot; Stop: &quot; + String(startStopVector[i].second));
         }

}
</code></pre>
<p>ist die idee und das vorgehen so gut?<br />
oder gibt es bedeutend bessere möglichkeiten?<br />
und wie sieht meine umsetzung bis jetzt aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141130</guid><dc:creator><![CDATA[asdasd]]></dc:creator><pubDate>Wed, 20 Sep 2006 12:51:07 GMT</pubDate></item><item><title><![CDATA[Reply to Methode zum einlesen und trennen von dateiinhalten gut? on Thu, 21 Sep 2006 06:20:49 GMT]]></title><description><![CDATA[<p>hm....ist das also eher nicht so gut?<br />
wäre toll wenn jemand etwas dazu sagen könnte!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141534</guid><dc:creator><![CDATA[hilfe?]]></dc:creator><pubDate>Thu, 21 Sep 2006 06:20:49 GMT</pubDate></item><item><title><![CDATA[Reply to Methode zum einlesen und trennen von dateiinhalten gut? on Thu, 21 Sep 2006 13:40:38 GMT]]></title><description><![CDATA[<p>hm...sorry wenn ich nochmal störe, aber wenn einer mal eine meinung dazu abgeben könnte wäre echt super!</p>
<p>will ja keinen mist verzapfen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141869</guid><dc:creator><![CDATA[hilfe?]]></dc:creator><pubDate>Thu, 21 Sep 2006 13:40:38 GMT</pubDate></item><item><title><![CDATA[Reply to Methode zum einlesen und trennen von dateiinhalten gut? on Thu, 21 Sep 2006 14:43:32 GMT]]></title><description><![CDATA[<p>Ja, di Funktion ist super...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141931</guid><dc:creator><![CDATA[GCoder]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:43:32 GMT</pubDate></item><item><title><![CDATA[Reply to Methode zum einlesen und trennen von dateiinhalten gut? on Fri, 22 Sep 2006 05:31:43 GMT]]></title><description><![CDATA[<p>hm....hört sich bisschen ironisch an <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1142284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1142284</guid><dc:creator><![CDATA[hilfe?]]></dc:creator><pubDate>Fri, 22 Sep 2006 05:31:43 GMT</pubDate></item></channel></rss>