<?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[anfänger frage: ascii file einlesen und verarbeiten]]></title><description><![CDATA[<p>hi</p>
<p>also ich bin noch relativ neu im geschäft und versuche grad ein macro zu schreiben mit dem ich einen file einlesen kann in dem in 2 spalten x und y werte drinne stehn, in der regel 20-40 werte. diese will ich dann plotten fitten etc.</p>
<p>bis jetzt muss ich das arraye mit den x und y werten noch mit hand vorher eintragen, ich würd es gern vom macro selber importieren lassen, hab aber keine idee wie ich es realisieren soll...</p>
<p>ich paste mal meinen code und einen stück aus einer &quot;import&quot; file, vlt kann mir ja einer hier helfen</p>
<p>ich benutze das root-macro vom CERN zum späteren fitten usw. das funktioniert auch problemlos...</p>
<pre><code class="language-cpp">{
gROOT-&gt;Reset();
//Ini_t n = 20;

  Double_t x[26] = {-3.9, -3.6, -3.3, -2.7, -2.4, -2.1
                                -2.8, -2.5, -1.2, -0.9, -0.6, -0.3
                                 0.0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8
                                  2.1, 2.4, 2.7, 3.0 3.3, 3.6, 3.9 };

  Double_t y[26] = {0.2832, 0.12966, 0.147, 0.153, 0.1586, 0.111
                    0.0886, 0.055, 0.0393, 0.0263, 0.0223, 0.0143
                    0.009, 0.0113, 0.0123, 0.012, 0.01 0.015 
                    0.025, 0.035, 0.042, 0.0586, 0.0546, 0.0376 0.0493, 0.0596};

TGraph *gr = new TGraph(26,x,y);
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,200,10,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

Double_t par[6];
g1 = new TF1(&quot;g1&quot;,&quot;gaus&quot;,-4.5,-2.5);
g2 = new TF1(&quot;g2&quot;,&quot;expo&quot;,3.0,7.0);
total = new TF1(&quot;total&quot;,&quot;gaus(0)+expo(3)&quot;,0.6,9.0);
total-&gt;SetLineColor(2);
gr-&gt;Fit(g1,&quot;R&quot;);
gr-&gt;Fit(g2,&quot;R+&quot;);
g1-&gt;GetParameters(&amp;par[0]);
g2-&gt;GetParameters(&amp;par[3]);
total-&gt;SetParameters(par);
gr-&gt;Fit(total,&quot;R+&quot;);

}
</code></pre>
<p>hier mal einen kleinen auszug aus einer import-file</p>
<blockquote>
<p>-4 0.22<br />
-3.9 0.22<br />
-3.8 0.14<br />
-3.7 0.14<br />
-3.6 0.19<br />
-3.5 0.25<br />
-3.4 0.23<br />
-3.3 0.2<br />
-3.2 0.18<br />
-3.1 0.18<br />
-3 0.11<br />
-2.9 0.24<br />
-2.8 0.18<br />
-2.7 0.19<br />
-2.6 0.11<br />
-2.5 0.16<br />
-2.4 0.06<br />
-2.3 0.05<br />
-2.2 0.12<br />
-2.1 0.05<br />
-2 0.07<br />
-1.9 0.05</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/topic/188420/anfänger-frage-ascii-file-einlesen-und-verarbeiten</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 03:59:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188420.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 31 Jul 2007 09:23:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 09:23:51 GMT]]></title><description><![CDATA[<p>hi</p>
<p>also ich bin noch relativ neu im geschäft und versuche grad ein macro zu schreiben mit dem ich einen file einlesen kann in dem in 2 spalten x und y werte drinne stehn, in der regel 20-40 werte. diese will ich dann plotten fitten etc.</p>
<p>bis jetzt muss ich das arraye mit den x und y werten noch mit hand vorher eintragen, ich würd es gern vom macro selber importieren lassen, hab aber keine idee wie ich es realisieren soll...</p>
<p>ich paste mal meinen code und einen stück aus einer &quot;import&quot; file, vlt kann mir ja einer hier helfen</p>
<p>ich benutze das root-macro vom CERN zum späteren fitten usw. das funktioniert auch problemlos...</p>
<pre><code class="language-cpp">{
gROOT-&gt;Reset();
//Ini_t n = 20;

  Double_t x[26] = {-3.9, -3.6, -3.3, -2.7, -2.4, -2.1
                                -2.8, -2.5, -1.2, -0.9, -0.6, -0.3
                                 0.0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8
                                  2.1, 2.4, 2.7, 3.0 3.3, 3.6, 3.9 };

  Double_t y[26] = {0.2832, 0.12966, 0.147, 0.153, 0.1586, 0.111
                    0.0886, 0.055, 0.0393, 0.0263, 0.0223, 0.0143
                    0.009, 0.0113, 0.0123, 0.012, 0.01 0.015 
                    0.025, 0.035, 0.042, 0.0586, 0.0546, 0.0376 0.0493, 0.0596};

TGraph *gr = new TGraph(26,x,y);
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,200,10,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

Double_t par[6];
g1 = new TF1(&quot;g1&quot;,&quot;gaus&quot;,-4.5,-2.5);
g2 = new TF1(&quot;g2&quot;,&quot;expo&quot;,3.0,7.0);
total = new TF1(&quot;total&quot;,&quot;gaus(0)+expo(3)&quot;,0.6,9.0);
total-&gt;SetLineColor(2);
gr-&gt;Fit(g1,&quot;R&quot;);
gr-&gt;Fit(g2,&quot;R+&quot;);
g1-&gt;GetParameters(&amp;par[0]);
g2-&gt;GetParameters(&amp;par[3]);
total-&gt;SetParameters(par);
gr-&gt;Fit(total,&quot;R+&quot;);

}
</code></pre>
<p>hier mal einen kleinen auszug aus einer import-file</p>
<blockquote>
<p>-4 0.22<br />
-3.9 0.22<br />
-3.8 0.14<br />
-3.7 0.14<br />
-3.6 0.19<br />
-3.5 0.25<br />
-3.4 0.23<br />
-3.3 0.2<br />
-3.2 0.18<br />
-3.1 0.18<br />
-3 0.11<br />
-2.9 0.24<br />
-2.8 0.18<br />
-2.7 0.19<br />
-2.6 0.11<br />
-2.5 0.16<br />
-2.4 0.06<br />
-2.3 0.05<br />
-2.2 0.12<br />
-2.1 0.05<br />
-2 0.07<br />
-1.9 0.05</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1335520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335520</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 09:23:51 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 09:39:48 GMT]]></title><description><![CDATA[<p>quant schrieb:</p>
<blockquote>
<p>...macro...</p>
</blockquote>
<p>*schubber*</p>
<p>Sorry - hat nix mit dem Thema zu tun.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/26836">@Topic</a>: Schau mal in den FAQ (oder einem C++-Buch/-Tutorial Deiner Wahl) unter &quot;Streams&quot;. Da findest Du alles, was Du brauchst.</p>
<p>irgendwie so:</p>
<pre><code class="language-cpp">ifstream in(&quot;MeineDatei.txt&quot;);
   double d;
   in &gt;&gt; d;
</code></pre>
<p>(Header, Fehlerbehandlung, ... habe ich erstmal weggelassen).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335533</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 31 Jul 2007 09:39:48 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 09:41:51 GMT]]></title><description><![CDATA[<p>Das Einlesen ist verflucht einfach, wirst dich wundern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
Erst einmal brauchst du natürlich die Strukturen, in die die Werte eingelesen werden sollen. Etwa so:</p>
<pre><code class="language-cpp">struct Point
{
    double x, y;
};
vector&lt;Point&gt; points; // Ein Array der Punkte, kann leicht vergrößert werden
</code></pre>
<p>Zum einlesen der Datei deklarierst du dir eine Variable ifstream, mit ihr öffnest du die Datei (<a href="http://www.cppreference.com/cppio/examples.html" rel="nofollow">klick</a>. Du deklarierst dir eine Variable vom Typ Point und liest in einer Schleife jeweils den x- und y-Wert ein und fügst den Punkt dem Array hinzu. Fertisch..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335534</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Tue, 31 Jul 2007 09:41:51 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 10:12:38 GMT]]></title><description><![CDATA[<p>huhu also ich bin nun soweit aber irgendwas geht noch schief ^^ vlt wisst ihr ja rat, hab erst mal alles auskommentiert was nich wichtig ist atm</p>
<pre><code class="language-cpp">//#include &lt;fstream&gt;

{
gROOT-&gt;Reset();
//Ini_t n = 20;

Double_t x[26], y[26];

	ifstream myFile;
	myFile.open (&quot;14.dat&quot;);  //liegt im selben folder
	myFile &gt;&gt; x &gt;&gt; y;
	myFile.close();

if (!myFile.eof())
{
cout &lt;&lt; &quot;x-wert: &quot;&lt;&lt; x &lt;&lt; &quot;    &quot;&lt;&lt; &quot;y-wert: &quot; &lt;&lt; y &lt;&lt; endl;

//  Double_t x[26] = {-3.9, -3.6, -3.3, -2.7, -2.4, -2.1
//		    -2.8, -2.5, -1.2, -0.9, -0.6, -0.3
//		    0.0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8
//                    2.1, 2.4, 2.7, 3.0 3.3, 3.6, 3.9 };

//  Double_t y[26] = {0.2832, 0.12966, 0.147, 0.153, 0.1586, 0.111
//                    0.0886, 0.055, 0.0393, 0.0263, 0.0223, 0.0143
//                    0.009, 0.0113, 0.0123, 0.012, 0.01 0.015 
//                    0.025, 0.035, 0.042, 0.0586, 0.0546, 0.0376 0.0493, 0.0596};

TGraph *gr = new TGraph(26,x,y);
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,200,10,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

//Double_t par[6];
//g1 = new TF1(&quot;g1&quot;,&quot;gaus&quot;,-4.5,-2.5);
//g2 = new TF1(&quot;g2&quot;,&quot;expo&quot;,3.0,7.0);
//total = new TF1(&quot;total&quot;,&quot;gaus(0)+expo(3)&quot;,0.6,9.0);
//total-&gt;SetLineColor(2);
//gr-&gt;Fit(g1,&quot;R&quot;);
//gr-&gt;Fit(g2,&quot;R+&quot;);
//g1-&gt;GetParameters(&amp;par[0]);
//g2-&gt;GetParameters(&amp;par[3]);
//total-&gt;SetParameters(par);
//gr-&gt;Fit(total,&quot;R+&quot;);
}
}
</code></pre>
<p>er ließt die werte irgendwie komisch ein und ich bekomme eine komische ausgabe in der shell:</p>
<blockquote>
<p>root [6] .x n.C<br />
x-wert: 0x17617e0 y-wert: 0x1601060<br />
Warning in <a href="TCanvas::ResizePad" rel="nofollow">TCanvas::ResizePad</a>: c1 width changed from 64000 to 10</p>
<p>Warning in <a href="TCanvas::ResizePad" rel="nofollow">TCanvas::ResizePad</a>: c1 height changed from 64000 to 10</p>
<p>Error in <a href="TGaxis::PaintAxis" rel="nofollow">TGaxis::PaintAxis</a>: length of axis is 0<br />
Error in <a href="TGaxis::PaintAxis" rel="nofollow">TGaxis::PaintAxis</a>: length of axis is 0<br />
root [7] Warning in <a href="TCanvas::ResizePad" rel="nofollow">TCanvas::ResizePad</a>: c1 width changed from 64000 to 10</p>
<p>Warning in <a href="TCanvas::ResizePad" rel="nofollow">TCanvas::ResizePad</a>: c1 height changed from 64000 to 10</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1335564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335564</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 10:12:38 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 10:16:23 GMT]]></title><description><![CDATA[<p>Es gibt keine Eingabe-Operatoren für Arrays, da mußt du schon die Elemente einzeln einlesen:</p>
<pre><code class="language-cpp">Double_t x[26],y[26];
for(int i=0;i&lt;26;++i)
  myFile&gt;&gt;x[i]&gt;&gt;y[i];
</code></pre>
<p>(btw, es ist erstaunlich, daß dein Programm durch den Compiler gekommen ist)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335567</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 31 Jul 2007 10:16:23 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 10:32:44 GMT]]></title><description><![CDATA[<p>ich danke vielmals funktioniert nun alles, zur vollständigkeit hänge ich den code mal an</p>
<pre><code>//#include &lt;fstream&gt;

{
gROOT-&gt;Reset();

Double_t x[88], y[88];

	ifstream myFile;
	myFile.open (&quot;14.dat&quot;);  //liegt im selben folder

		if (!myFile)
 		   {
      		   cout &lt;&lt; &quot;Fehler beim Oeffnen der Datei!\n&quot;;
       		   exit(1);
                   }

	for(int i=0;i&lt;88;++i)
        myFile&gt;&gt;x[i]&gt;&gt;y[i];

	myFile.close();

if (!myFile.eof())
{
for (int i=0;i&lt;88;i++)
cout &lt;&lt; &quot;x-wert: &quot;&lt;&lt; x[i] &lt;&lt; &quot;    &quot;&lt;&lt; &quot;y-wert: &quot; &lt;&lt; y[i] &lt;&lt; endl;

TGraph *gr = new TGraph(88,x,y);
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,400,20,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1335572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335572</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 10:32:44 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 10:43:47 GMT]]></title><description><![CDATA[<p>quant schrieb:</p>
<blockquote>
<p>ich danke vielmals funktioniert nun alles, zur vollständigkeit hänge ich den code mal an</p>
</blockquote>
<p>Hallo quant,</p>
<p>Normalerweise sollte man so ein Format wie folgt einlesen.</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;iterator&gt; // istream_iterator&lt;&gt;
#include &lt;vector&gt;

typedef double Double_t;
struct XY
{
    Double_t m_x, m_y;
};
std::istream&amp; operator&gt;&gt;( std::istream&amp; in, XY&amp; xy )
{
    return in &gt;&gt; xy.m_x &gt;&gt; xy.m_y;
}

int main()
{
    using namespace std;
    // --   Einlesen
    ifstream myfile( &quot;14.dat&quot; );
    vector&lt; XY &gt; xy( (istream_iterator&lt; XY &gt;( myfile )), istream_iterator&lt; XY &gt;() );
    // jetzt ist alles in 'xy'
</code></pre>
<p>aber da Du die Koordinaten in einzelnen Feldern benötigst, kannst Du sie dann auch gleich in der Form einlesen. Also:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

typedef double Double_t;

int main()
{
    using namespace std;
    // --   Einlesen
    ifstream myfile( &quot;14.dat&quot; );
    vector&lt; Double_t &gt; x;
    vector&lt; Double_t &gt; y;
    for( double xx, yy; myfile &gt;&gt; xx &gt;&gt; yy; )
    {
        x.push_back( xx );
        y.push_back( yy );
    }

    // --   und benutzen
    TGraph *gr = new TGraph( x.size(), &amp;x[0], &amp;y[0] ); 
    // usw.
</code></pre>
<p>Bem.: Koordinaten in dieser Form - also einzeln - abzulegen ist übrigens schlechter Stil, weil ziemlich unhandlich. Wo kommt denn das TGraph&amp;Co her?</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335577</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335577</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 31 Jul 2007 10:43:47 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 11:01:52 GMT]]></title><description><![CDATA[<p>Tgraph und co sind fuctionen aus dem root tool vom CERN ist eine wissenschaftliche erweiterung für c oder wie man das genau nennt, kenne mich mit all dem noch nich so aus, code erst seit 4tagen ^^</p>
<p>hab dir die page mal gelinkt</p>
<p><a href="http://root.cern.ch/" rel="nofollow">http://root.cern.ch/</a></p>
<p>lg</p>
<p>edit:</p>
<p>ich hab grad versucht es mal umzuschreiben, bekomme jetzt aber einen fehler:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

typedef double Double_t;
gROOT-&gt;Reset();

int main()
{
    using namespace std;
    // --   Einlesen
    ifstream myfile( &quot;14.dat&quot; );
    vector&lt; Double_t &gt; x;
    vector&lt; Double_t &gt; y;
    for( double xx, yy; myfile &gt;&gt; xx &gt;&gt; yy; )
    {
        x.push_back( xx );
        y.push_back( yy );
    }

TGraph *gr = new TGraph( x.size(), &amp;x[0], &amp;y[0] );
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,400,20,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

//Double_t par[6];
g1 = new TF1(&quot;g1&quot;,&quot;gausn&quot;,-4.0,-0.0);
//g2 = new TF1(&quot;g2&quot;,&quot;expo&quot;,3.0,7.0);
//total = new TF1(&quot;total&quot;,&quot;gaus(0)+expo(3)&quot;,0.6,9.0);
//total-&gt;SetLineColor(2);
gr-&gt;Fit(g1,&quot;R&quot;);
//gr-&gt;Fit(g2,&quot;R+&quot;);
//g1-&gt;GetParameters(&amp;par[0]);
//g2-&gt;GetParameters(&amp;par[3]);
//total-&gt;SetParameters(par);
//gr-&gt;Fit(total,&quot;R+&quot;);
}
</code></pre>
<blockquote>
<p>root [18] .x fit.C<br />
Error: x already declared as different type. ~vector&lt;double,allocator&lt;double&gt; &gt;( ) called<br />
fit.C:11:<br />
*** Interpreter error recovered ***</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1335582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335582</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 11:01:52 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 11:45:46 GMT]]></title><description><![CDATA[<p>quant schrieb:</p>
<blockquote>
<p>ich hab grad versucht es mal umzuschreiben, bekomme jetzt aber einen fehler:<br />
root [18] .x fit.C</p>
<blockquote>
<p>Error: x already declared as different type. ~vector&lt;double,allocator&lt;double&gt; &gt;( ) called<br />
fit.C:11:<br />
*** Interpreter error recovered ***</p>
</blockquote>
</blockquote>
<p>Ist das wirklich in dieser Zeile:</p>
<pre><code class="language-cpp">x.push_back( xx );
</code></pre>
<p>?</p>
<p>Was für einen Compiler benutzt Du? Das 'Interpreter' verwirrt mich etwas ...</p>
<p>Edit: lass mal das 'typedef double Double_t' weg; das war nur für mein Testprogramm!</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335627</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 31 Jul 2007 11:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 12:36:17 GMT]]></title><description><![CDATA[<p>hi</p>
<p>also ich use den standart linux compiler g++ und bin in der root-console vom root-tool ... habs nochma geändert und gestartet...</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;

gROOT-&gt;Reset();

{
    using namespace std;
    // --   Einlesen
    ifstream myfile( &quot;14.dat&quot; );
    vector&lt; Double_t &gt; x;
    vector&lt; Double_t &gt; y;
    for( double xx, yy; myfile &gt;&gt; xx &gt;&gt; yy; )
    {
        x.push_back( xx );
        y.push_back( yy );
    }

TGraph *gr = new TGraph( x.size(), &amp;x[0], &amp;y[0] );
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,400,20,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);

//Double_t par[6];
g1 = new TF1(&quot;g1&quot;,&quot;gausn&quot;,-4.0,0.0);
//g2 = new TF1(&quot;g2&quot;,&quot;expo&quot;,3.0,7.0);
//total = new TF1(&quot;total&quot;,&quot;gaus(0)+expo(3)&quot;,0.6,9.0);
//total-&gt;SetLineColor(2);
gr-&gt;Fit(g1,&quot;R&quot;);
//gr-&gt;Fit(g2,&quot;R+&quot;);
//g1-&gt;GetParameters(&amp;par[0]);
//g2-&gt;GetParameters(&amp;par[3]);
//total-&gt;SetParameters(par);
//gr-&gt;Fit(total,&quot;R+&quot;);
}
</code></pre>
<p>bekomme nun eine andere meldung:</p>
<blockquote>
<p>root [6] .x fit.C<br />
Warning: Unknown type 'yy;' in function argument handled as int fit.C:13:</p>
<p>*** Break *** segmentation violation<br />
Using host libthread_db library &quot;/lib/libthread_db.so.1&quot;.<br />
Attaching to program: /proc/8274/exe, process 8274<br />
[Thread debugging using libthread_db enabled]<br />
[New Thread 47433660509808 (LWP 8274)]<br />
0x00002b24022d1af5 in waitpid () from /lib/libc.so.6<br />
error detected on stdin<br />
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]<br />
Detaching from program: /proc/8274/exe, process 8274<br />
Root &gt;</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1335688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335688</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 12:36:17 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 12:41:46 GMT]]></title><description><![CDATA[<p>EDIT: Inzwischen hast Du einen neuene Fehler gepostet. Dies hier bezieht sich auf &quot;die Fehlermeldung mit x&quot; (aber kann es sein, dass Du bei y/yy wieder einen Tippfehler hast ?):</p>
<blockquote>
<p>Ich wette ja, dass Du entweder irgendwo ein 'x' vergessen (z.B. statt <code>&quot;double xx&quot;</code> nur <code>&quot;double x&quot;</code> ) oder tatsächlich schon eine (vielleicht globale oder per #include importierte) Variable names &quot;x&quot; hast.</p>
<p>Spaßeshelber kannst Du ja mal Deinen Vector umbenennen, also statt</p>
<p>quant schrieb:</p>
<blockquote>
<p>....</p>
<pre><code class="language-cpp">vector&lt; double &gt; x;
</code></pre>
</blockquote>
<p>dann ein</p>
<pre><code class="language-cpp">vector&lt; double &gt; xVec;
</code></pre>
</blockquote>
<p>Ach ja: Eine for-Schleife ist nicht unbedingt die Methode der Wahl für das, was Du vorhast. Da hätte ich ein while() genommen.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335689</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 31 Jul 2007 12:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger frage: ascii file einlesen und verarbeiten on Tue, 31 Jul 2007 13:59:36 GMT]]></title><description><![CDATA[<p>hmm ich muss gestehen ich bin mit der frage grad überfordert aber einen syntax-fehler finde ich auch nicht...</p>
<p>naja jedenfalls läuft es ja mit dem anderen code... was ich jetzt noch gerne machen würde ist meine gaus-gefittete fkt. integrieren, nur weiss ich grad garnich wie ich das anstellen soll ^^</p>
<p>hier mal meinen code wie weit er atm ist:</p>
<pre><code class="language-cpp">//#include &lt;fstream&gt;

{
gROOT-&gt;Reset();
gStyle-&gt;SetOptFit();

Double_t x[88], y[88];

    ifstream myFile;
    myFile.open (&quot;14.dat&quot;);  //liegt im selben folder

        if (!myFile)
 	    {
      	    cout &lt;&lt; &quot;Fehler beim Oeffnen der Datei!\n&quot;;
       	    exit(1);
            }

	       for(int i=0;i&lt;88;++i)
               myFile&gt;&gt;x[i]&gt;&gt;y[i];

    myFile.close();
    if (!myFile.eof())

{

for (int i=0;i&lt;88;i++)
cout &lt;&lt; &quot;x-wert: &quot;&lt;&lt; x[i] &lt;&lt; &quot;    &quot;&lt;&lt; &quot;y-wert: &quot; &lt;&lt; y[i] &lt;&lt; endl;

TGraph *gr = new TGraph(88,x,y);
TCanvas *c1 = new TCanvas(&quot;c1&quot;,&quot;Graph Draw Options&quot;,400,20,600,400);
gr-&gt;SetFillColor(40);
gr-&gt;Draw(&quot;AB*&quot;);
gr-&gt;GetXaxis()-&gt;SetTitle(&quot;Rapidity&quot;);
gr-&gt;GetYaxis()-&gt;SetTitle(&quot;N(i) / DELTA Y&quot;);
gr-&gt;GetXaxis()-&gt;CenterTitle();
gr-&gt;GetYaxis()-&gt;CenterTitle();

g1 = new TF1(&quot;g1&quot;,&quot;gausn&quot;,-4.0,-0.0);

gr-&gt;Fit(g1,&quot;R&quot;);

gSystem-&gt;ProcessEvents();
TImage *img = TImage::Create();
img-&gt;FromPad(c1);
img-&gt;WriteImage(&quot;canvas.png&quot;);

}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1335742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335742</guid><dc:creator><![CDATA[quant]]></dc:creator><pubDate>Tue, 31 Jul 2007 13:59:36 GMT</pubDate></item></channel></rss>