<?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[Einlesen einer Textdatei in eine Matrix]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich stehe momentan vor einem Problem. Ich soll ein Programm schreiben.... komme aber einfach nicht mehr weiter.<br />
Vorliegen habe ich eine Textdatei, wie nachfolgend zu sehen ist. Dabei handelt es sich um Winddaten:</p>
<p>2006-01-11 00:00:00; -179,5; -83,0; -3,04; 3,73;<br />
2006-01-11 00:00:00; -179,5; -82,5; -2,74; 3,57;<br />
2006-01-11 00:00:00; -179,5; -82,0; -2,40; 3,60;<br />
2006-01-11 00:00:00; -179,5; -81,5; -1,86; 3,50;<br />
2006-01-11 00:00:00; -179,5; -81,0; -0,93; 2,74;<br />
2006-01-11 00:00:00; -179,5; -80,5; -0,12; 2,24;<br />
2006-01-11 00:00:00; -179,5; -80,0; 0,44; 2,00;<br />
2006-01-11 00:00:00; -179,5; -79,5; 0,72; 2,14;<br />
2006-01-11 00:00:00; -179,5; -79,0; 0,85; 2,08;<br />
2006-01-11 00:00:00; -179,5; -78,5; 1,24; 1,60;</p>
<p>Insgesamt beinhaltet die Textdatei fünf Spalten, die jeweils durch ein Komma getrennt wurden. Diese möchte ich in eine Matrix einlesen. Die Werte der letzten beiden Spalten stellen die beiden Komponenten eines Windvektors dar. Aus diesen beiden Werten muss ich jeweils den Windvektor in Länge und Richtung bestimmten. Dazu sind die beiden Funktion &quot;windspeed&quot; und &quot;winddirection&quot; da. Die Ergebnisse der beiden Funktionen müssen dann ebenfalls in der Matrix gespeichert werden - in einer 6. und 7. Spalte.<br />
Zum Schluss möchte ich auf die Matix zugreifen können. Einzelne Werte oder auch die gesamte Matrix sollen ausgegeben werden.<br />
Nachfolgend findet ihr die aktuelle Version meines Programms. Ausgabe der Matrix funktioniert bei mir nicht. Kann mir jemand von euch helfen? Wo liegt mein Fehler? Vielen Dank schon im voraus.</p>
<p>Liebe Grüße<br />
Nicole</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cmath&gt;
#include &lt;vector&gt;

using namespace std;

const float pi = 3.1415;

//Function windspeed
float windspeed (float u, float v) {
    float z;
    z = sqrt(u*u + v*v);
    return z;
}

//Function winddirection
float direction (float u, float v) {
    float z;
    z = atan(v/u) * (180/pi);
    return z;
}

int main() {
    vector &lt;string&gt; V, W;                               //defining a vector
    string line;                                        //defining a string
    int i = 0;                                          //startposition of V
    size_t pos = 0;                                     //declare the position of &quot;Semicolon&quot;
    const int column = 5;                               //number of columns of the data

    ifstream read;                                      //class ifstream
    read.open(&quot;Testfile_Winddata.txt&quot;);                              //open data before use
    if(!read.is_open())                                 //check if data can be open
        cerr &lt;&lt; &quot;Failed to open data!&quot; &lt;&lt; endl;         //Data can not be open
    getline(read, line);                                

    while (getline(read,line)) {                        //read line by line of the data
        V.push_back(line);                              //vector V gets a textline

        while (!V[i].empty()) {                
            pos = V[i].find(&quot;;&quot;);                       //find the position of the first &quot;semicolon&quot;   
            if (pos == string::npos) {                  //if no &quot;semicolon&quot; can be found
                cout &lt;&lt; &quot;Error!&quot; &lt;&lt; endl;
                W.push_back(V[i]);
                break;
            }

            W.push_back(V[i].substr(0,pos));            /*the line of V[i] is cut from the beginning 
                                                        to the first &quot;Semicolon&quot; and inserted in W*/
            V[i]=V[i].substr(pos+1);                    //string up to the first &quot;Semicolon&quot; is deleted
        }
        i++;                                            //get the next vector-entry
    }

    int j = 0;                                          //define j as the number of lines in the textdata

    int e = W.size()/column;
    float (*matrix) [column+2] = new float [e][column+2];    //define a matrix

    for (int t = 0; t &lt; W.size(); t = t + column) {
        for (int k = 0; k &lt; column; k++) {
            matrix[j][k] = atof(W[t+k].c_str());        //atof: change ascii to float
        }

        matrix[j][column] = windspeed(matrix[j][column-1], matrix[j][column-2]);    //use function windspeed
        matrix[j][column+1] = direction(matrix[j][column-1], matrix[j][column-2]);  //use function direction
        j++;                                                                        //go to the next line
    }

    read.close();                                       //close data after use

    cout &lt;&lt; matrix[2][4];

    cin.get();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/318854/einlesen-einer-textdatei-in-eine-matrix</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Jul 2026 06:30:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318854.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Jul 2013 08:31:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Mon, 29 Jul 2013 08:31:14 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich stehe momentan vor einem Problem. Ich soll ein Programm schreiben.... komme aber einfach nicht mehr weiter.<br />
Vorliegen habe ich eine Textdatei, wie nachfolgend zu sehen ist. Dabei handelt es sich um Winddaten:</p>
<p>2006-01-11 00:00:00; -179,5; -83,0; -3,04; 3,73;<br />
2006-01-11 00:00:00; -179,5; -82,5; -2,74; 3,57;<br />
2006-01-11 00:00:00; -179,5; -82,0; -2,40; 3,60;<br />
2006-01-11 00:00:00; -179,5; -81,5; -1,86; 3,50;<br />
2006-01-11 00:00:00; -179,5; -81,0; -0,93; 2,74;<br />
2006-01-11 00:00:00; -179,5; -80,5; -0,12; 2,24;<br />
2006-01-11 00:00:00; -179,5; -80,0; 0,44; 2,00;<br />
2006-01-11 00:00:00; -179,5; -79,5; 0,72; 2,14;<br />
2006-01-11 00:00:00; -179,5; -79,0; 0,85; 2,08;<br />
2006-01-11 00:00:00; -179,5; -78,5; 1,24; 1,60;</p>
<p>Insgesamt beinhaltet die Textdatei fünf Spalten, die jeweils durch ein Komma getrennt wurden. Diese möchte ich in eine Matrix einlesen. Die Werte der letzten beiden Spalten stellen die beiden Komponenten eines Windvektors dar. Aus diesen beiden Werten muss ich jeweils den Windvektor in Länge und Richtung bestimmten. Dazu sind die beiden Funktion &quot;windspeed&quot; und &quot;winddirection&quot; da. Die Ergebnisse der beiden Funktionen müssen dann ebenfalls in der Matrix gespeichert werden - in einer 6. und 7. Spalte.<br />
Zum Schluss möchte ich auf die Matix zugreifen können. Einzelne Werte oder auch die gesamte Matrix sollen ausgegeben werden.<br />
Nachfolgend findet ihr die aktuelle Version meines Programms. Ausgabe der Matrix funktioniert bei mir nicht. Kann mir jemand von euch helfen? Wo liegt mein Fehler? Vielen Dank schon im voraus.</p>
<p>Liebe Grüße<br />
Nicole</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cmath&gt;
#include &lt;vector&gt;

using namespace std;

const float pi = 3.1415;

//Function windspeed
float windspeed (float u, float v) {
    float z;
    z = sqrt(u*u + v*v);
    return z;
}

//Function winddirection
float direction (float u, float v) {
    float z;
    z = atan(v/u) * (180/pi);
    return z;
}

int main() {
    vector &lt;string&gt; V, W;                               //defining a vector
    string line;                                        //defining a string
    int i = 0;                                          //startposition of V
    size_t pos = 0;                                     //declare the position of &quot;Semicolon&quot;
    const int column = 5;                               //number of columns of the data

    ifstream read;                                      //class ifstream
    read.open(&quot;Testfile_Winddata.txt&quot;);                              //open data before use
    if(!read.is_open())                                 //check if data can be open
        cerr &lt;&lt; &quot;Failed to open data!&quot; &lt;&lt; endl;         //Data can not be open
    getline(read, line);                                

    while (getline(read,line)) {                        //read line by line of the data
        V.push_back(line);                              //vector V gets a textline

        while (!V[i].empty()) {                
            pos = V[i].find(&quot;;&quot;);                       //find the position of the first &quot;semicolon&quot;   
            if (pos == string::npos) {                  //if no &quot;semicolon&quot; can be found
                cout &lt;&lt; &quot;Error!&quot; &lt;&lt; endl;
                W.push_back(V[i]);
                break;
            }

            W.push_back(V[i].substr(0,pos));            /*the line of V[i] is cut from the beginning 
                                                        to the first &quot;Semicolon&quot; and inserted in W*/
            V[i]=V[i].substr(pos+1);                    //string up to the first &quot;Semicolon&quot; is deleted
        }
        i++;                                            //get the next vector-entry
    }

    int j = 0;                                          //define j as the number of lines in the textdata

    int e = W.size()/column;
    float (*matrix) [column+2] = new float [e][column+2];    //define a matrix

    for (int t = 0; t &lt; W.size(); t = t + column) {
        for (int k = 0; k &lt; column; k++) {
            matrix[j][k] = atof(W[t+k].c_str());        //atof: change ascii to float
        }

        matrix[j][column] = windspeed(matrix[j][column-1], matrix[j][column-2]);    //use function windspeed
        matrix[j][column+1] = direction(matrix[j][column-1], matrix[j][column-2]);  //use function direction
        j++;                                                                        //go to the next line
    }

    read.close();                                       //close data after use

    cout &lt;&lt; matrix[2][4];

    cin.get();
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2341904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341904</guid><dc:creator><![CDATA[nickey1989]]></dc:creator><pubDate>Mon, 29 Jul 2013 08:31:14 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Mon, 29 Jul 2013 11:42:40 GMT]]></title><description><![CDATA[<p>Sind da wirklich Kommas statt Dezimalpunke? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
<p>Allgemein hast du hier ein paar Fehler in der Herandgehensweise:<br />
1. Datenstrukturen:<br />
Hier ist keine Matrix gefragt. Die Daten in jeder Spalte haben jeweils eine völlig unterschiedliche Bedeutung, auch wenn sie auf den ersten Blick alle wie Zahlen aussehen. Es wäre wohl eher ein komplexer Datentyp gefragt:</p>
<pre><code>class winddata
{
  double x,y; // Keine Ahnung, was die ersten beiden Spalten sein sollen, ich habe einfach mal geraten
  double vx, vy;
  double angle, speed;
};
</code></pre>
<p>Dann schreibst du eine saubere Lesefunktion für diesen Datentyp und machst einen vector von diesem Datentyp.<br />
2. Nicht-Benutzung der Standardbibliothek: Du kennst offensichtlich vector und streams, da gibt es keine Entschuldigung für Frickeleien mit new und atof. Sein lassen.<br />
3. Falsch gerechnet/nicht gekannt: <a href="https://www.google.de/search?&amp;q=atan2" rel="nofollow">Google: atan2</a>; viele Implementierungen kennen auch pi; Winkel in Grad sind ungewöhnlich, da unpraktisch<br />
4. Schon in 1. angedeutet: Kapselung! Wie die Datei gelesen wird, steht in einer passenden Lesefunktion, nicht alles in der main. Optimalerweise steht dort nur noch so etwas wie</p>
<pre><code>vector&lt;winddata&gt; data;
for (winddata w; stream &gt;&gt; w; ) data.push_back(w);
</code></pre>
<p>5. Viele Umwege: Anstatt aus dem Stream in einen string zu lesen und diesen zu zerlegen, lies doch einfach direkt aus dem Stream. Dieser ist dafür gemacht, formatierte Daten (also zum Beispiel auch Zahlen mit Komma als Dezimaltrennstelle) zu lesen. Der kann das viel besser als du.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341965</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341965</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 29 Jul 2013 11:42:40 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Mon, 29 Jul 2013 19:30:56 GMT]]></title><description><![CDATA[<p>Hallo Nicole,</p>
<p>Dein offensichtlicher Fehler liegt darin, dass Du die Matrix gar nicht ausgibst sondern nur das eine Element ' <code>matrix[2][4]</code> '. Ab Zeile 73 könnte es heißen:</p>
<pre><code>for( int ln = 0; ln &lt; e; ++ln )
    {
        for( int sp = 0; sp &lt; column+2; ++sp )
            cout &lt;&lt; matrix[ln][sp] &lt;&lt; &quot;; &quot;;
        cout &lt;&lt; endl;
    }
</code></pre>
<p>Du erhältst dann als Ausgabe:</p>
<pre><code>2006; -179; -82; -2; 3; 3.60555; -33.6911;
2006; -179; -82; -2; 3; 3.60555; -33.6911;
2006; -179; -81; -1; 3; 3.16228; -18.4355;
2006; -179; -81; -0; 2; 2; -0;
2006; -179; -80; -0; 2; 2; -0;
2006; -179; -80; 0; 2; 2; 0;
2006; -179; -79; 0; 2; 2; 0;
2006; -179; -79; 0; 2; 2; 0;
2006; -179; -78; 1; 1; 1.41421; 45.0013;
</code></pre>
<p>Dir fällt vielleicht auf, dass bei allen Zahlen, die 'gelesen' wurden ( <code>atof</code> ), die Nachkommastellen fehlen. Das liegt daran, dass Du atof und nicht das Einlesen vom Stream nutzt. Versuche mal dieses Codeschnipsel:</p>
<pre><code>cin.imbue( locale(&quot;deu&quot;) ); // auf deutsche Locale umstellen
    for( float zahl; cin &gt;&gt; zahl; )
        cout &lt;&lt; &quot;--&gt; &quot; &lt;&lt; zahl &lt;&lt; endl;
</code></pre>
<p>dann kann der Dialog z.B. so aussehen:</p>
<pre><code>-179,5
--&gt; -179.5
3,50
--&gt; 3.5
0,0002
--&gt; 0.0002
</code></pre>
<p>wie Du siehst werden die Zahlen im deutschen Format (mit Komma als Dezimaltrenner) gelesen und im englischen Format (mit '.') wieder ausgegeben. Der Name der Locale (hier &quot;deu&quot;) ist von Deiner Entwicklungsumgebung abhängig und kann anders lauten. &quot;deu&quot; ist korrekt für MS-VS.</p>
<p>Ansonsten stimme ich allen Aussagen, die SeppJ aufgelistet hat, zu. Ich gehe bei der <code>class winddata</code> sogar noch einen Schritt weiter und würde die Member angle und speed weglassen und statt dessen zwei Methoden anbieten, die das aus dem Windvektor bestimmen.</p>
<p>Beim bestimmen der Windrichtung solltest Du genau darauf achten, wie die beiden Windkomponenten definiert sind, und die Tatsache bedenken, dass Windrichtung immer die Richtung ist aus der der Wind kommt. Der Windvektor zeigt wahrscheinlich in die Richtung in die der Wind weht!</p>
<p>Zum Einlesen so einer Struktur schaue Dir mal die <a href="http://www.c-plusplus.net/forum/p2340507#2340507" rel="nofollow">kleine Übung in dem Beitrag weiter unten</a> an und zum Überlesen von ';' kann <a href="http://www.c-plusplus.net/forum/p2016220#2016220" rel="nofollow">dieser Thread</a> nützlich sein. Falls Du darüber hinaus Fragen hast, so melde Dich noch mal.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2342106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2342106</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 29 Jul 2013 19:30:56 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Wed, 31 Jul 2013 12:30:12 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe nun etwas an meinem Programm gebastelt. Es sieht nun so aus - also wie ihr sehen könnt etwas abgespeckt:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;cmath&gt;
#include &lt;vector&gt;
#include &lt;iterator&gt;

using namespace std;

const float pi = 3.1415;

//Class Winddata
class winddata {               
    string date;                //defining a string representing the date
    double lon, lat;            //defining longitude and latitude
    double UGRD, VGRD;          //defining the two components of the windvector 
    double speed, angle;        //defining windspeed and -angle
};  

//Funktion readfile
void readfile() {
    vector &lt;string&gt; V;                  //defining a vector 
    string t;                           //defining a text
    ifstream read;
    read.open(&quot;Testfile_Winddata.txt&quot;); //open file
    while(getline(read, t,';')) {
    V.push_back(t);
    }
    copy(V.begin(), V.end(), ostream_iterator&lt;string&gt;(cout, &quot; &quot;));      //Output of the vector

    read.close();                       //close file
}

//Function windspeed
float windspeed (float u, float v) {
    float z;
    z = sqrt(u*u + v*v);
    return z;
}

//Function winddirection
float direction (float u, float v) {
    float z;
    z = atan2(v,u) * (180/pi);
    return z;
}

int main() {

    readfile();

    system(&quot;PAUSE&quot;);
    return 0;
}
</code></pre>
<p>Als Ausgabe erhalte ich dann folgendes:</p>
<pre><code>2006-01-11 00:00:00     -179.5  -83.0   -3.04   3.73
2006-01-11 00:00:00     -179.5  -82.5   -2.74   3.57
2006-01-11 00:00:00     -179.5  -82.0   -2.40   3.60
2006-01-11 00:00:00     -179.5  -81.5   -1.86   3.50
2006-01-11 00:00:00     -179.5  -81.0   -0.93   2.74
2006-01-11 00:00:00     -179.5  -80.5   -0.12   2.24
2006-01-11 00:00:00     -179.5  -80.0   0.44    2.00
2006-01-11 00:00:00     -179.5  -79.5   0.72    2.14
2006-01-11 00:00:00     -179.5  -79.0   0.85    2.08
2006-01-11 00:00:00     -179.5  -78.5   1.24    1.60
</code></pre>
<p>Ich habe nun eine Klasse &quot;winddata&quot; angelegt und die Lesefunktion &quot;readfile&quot; angelegt. Nun weiß ich leider nicht, wie man die einzelnen Daten den entsprechenden Klassenelementen zuweist. Pro Zeile müsste dann ja ein Objekt der Klasse &quot;winddata&quot; angelegt werden. Wie lese ich direkt aus dem Stream?</p>
<p>Vielen Dank und liebe Grüße<br />
Nicole</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2342527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2342527</guid><dc:creator><![CDATA[nickey1989]]></dc:creator><pubDate>Wed, 31 Jul 2013 12:30:12 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Wed, 31 Jul 2013 19:33:37 GMT]]></title><description><![CDATA[<p>Hallo Nicole,</p>
<p>nickey1989 schrieb:</p>
<blockquote>
<pre><code>//Class Winddata
class winddata {               
    string date;                //defining a string representing the date
    double lon, lat;            //defining longitude and latitude
// ...
</code></pre>
</blockquote>
<p>wenn das die geographische Länge und Breite sein soll, dann ist bei Lon=-179,5 und Lat=-83,0 aber ziemlich viel Eis in der Nähe <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="😉"
    /></p>
<p>nickey1989 schrieb:</p>
<blockquote>
<p>Als Ausgabe erhalte ich dann folgendes:</p>
<pre><code>2006-01-11 00:00:00     -179.5  -83.0   -3.04   3.73
2006-01-11 00:00:00     -179.5  -82.5   -2.74   3.57
...
</code></pre>
</blockquote>
<p>das widerspricht sich mit dem Inhalt Deines ersten Beitrags. Du liest Zeichen ein und gibst Zeichen aus, demnach stehen die Zahlen mit '.' als Dezimaltrenner in der Datei, oben steht es mit ',' - Du musst Dich schon entscheiden.</p>
<p>nickey1989 schrieb:</p>
<blockquote>
<p>Ich habe nun eine Klasse &quot;winddata&quot; angelegt und die Lesefunktion &quot;readfile&quot; angelegt. Nun weiß ich leider nicht, wie man die einzelnen Daten den entsprechenden Klassenelementen zuweist. Pro Zeile müsste dann ja ein Objekt der Klasse &quot;winddata&quot; angelegt werden. Wie lese ich direkt aus dem Stream?</p>
</blockquote>
<p>Hast Du den Beitrag hinter diesem Link gelesen?</p>
<p>Werner Salomon schrieb:</p>
<blockquote>
<p>Zum Einlesen so einer Struktur schaue Dir mal die <a href="http://www.c-plusplus.net/forum/p2340507#2340507" rel="nofollow">kleine Übung in dem Beitrag weiter unten</a> an ....</p>
</blockquote>
<p>dort ist es im Prinzip erklärt.</p>
<p>Hier Dein Programm etwas aufgemotzt:</p>
<pre><code>#include &lt;cmath&gt; // std::atan2, std::sqrt
#include &lt;fstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

template&lt; char C &gt;
std::istream&amp; Char( std::istream&amp; in )
{   // Helferlein, um ein Zeichen 'C' zu überlesen
    char c;
    if( in &gt;&gt; c &amp;&amp; c != C )
        in.setstate( std::ios_base::failbit );
    return in;
}

namespace
{
    const double PI = std::acos( -1.0 );
    const double RAD2GRAD = 180./PI;
}

//Class Winddata
class winddata {
public:
    double speed() const
    {
        return std::sqrt( UGRD*UGRD + VGRD*VGRD );
    }
    double angle() const
    {
        // Bem.: um hier als Ergebnis die Windrichtung (Kompasskurs) zu bekommen, muss
        //  UGRD die Südkomponente und VGRD die Westkomponente des Windes sein!
        //  - ist das so?
        return std::atan2(VGRD, UGRD) * RAD2GRAD;
    }
    friend std::istream&amp; operator&gt;&gt;( std::istream&amp; in, winddata&amp; d );

private:
    std::string date;           //defining a string representing the date
    double lon, lat;            //defining longitude and latitude
    double UGRD, VGRD;          //defining the two components of the windvector
};  

// --   Lesefunktion für winddata
std::istream&amp; operator&gt;&gt;( std::istream&amp; in, winddata&amp; d )
{
    getline( in &gt;&gt; std::ws, d.date, ';' );
    in &gt;&gt; d.lon &gt;&gt; Char&lt;';'&gt; &gt;&gt; d.lat &gt;&gt; Char&lt;';'&gt;;
    in &gt;&gt; d.UGRD &gt;&gt; Char&lt;';'&gt; &gt;&gt; d.VGRD &gt;&gt; Char&lt;';'&gt;;
    return in;
}

int main()
{ 
    using namespace std;
    vector&lt; winddata &gt; W;
    ifstream read( &quot;Testfile_Winddata.txt&quot; );
    if( !read.is_open() )
    {
        cerr &lt;&lt; &quot;Failed to open data!&quot; &lt;&lt; endl;
        return -2;
    }
    read.imbue( locale(&quot;deu&quot;) ); // &lt;== deutsches Zahlenformat, falls die Zahlen mit ',' als Dezimaltrenner geschrieben werden 
    for( winddata w; read &gt;&gt; w; )
        W.push_back( w );
    cout &lt;&lt; W.size() &lt;&lt; &quot; Eintraege gelesen&quot; &lt;&lt; endl;
    // usw.
    cin.get();
    return 0;
}
</code></pre>
<p>falls Du Fragen hast, bitte frage.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2342614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2342614</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 31 Jul 2013 19:33:37 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Mon, 05 Aug 2013 12:34:24 GMT]]></title><description><![CDATA[<p>Hallo Werner,</p>
<p>ein paar Fragen hätte ich schon noch zu deinem Programm:<br />
Die Template-Funktion ist dazu dar, ein Zeichen, also den Semikolon zu überlesen. Die Zeile 12 verstehe ich jedoch nicht. Was bewirkt die Funktion &quot;setstate&quot;? Die Google-Suche hat mir nicht wirklich weitergeholfen.</p>
<p>Die Einteilung der Klasse in public und private verursacht bei mir Probleme. Es kommt die Fehlermeldung: Auf &quot;Member &quot;winddata::date&quot; (deklariert in Zeile 30)&quot; kann nicht zugegriffen werden. Deshalb habe ich das Schlüsselwort &quot;private&quot; gelöscht. Ich habe nun die gesamten Elemente der Klasse als &quot;public&quot; deklariert.</p>
<p>Ich habe dann ein Objekt winddata_object erzeugt, wie man im Code unten sehen kann. Ich wollte dann einzele Elemente dieses Objektes ausgeben lassen. Aber ich erhalte keine bzw. falsche Werte. Wo liegt mein Fehler?</p>
<pre><code>winddata winddata_object;
cout &lt;&lt; winddata_object.date &lt;&lt; endl;
cout &lt;&lt; winddata_object.lat &lt;&lt; endl;
</code></pre>
<p>Liebe Grüße<br />
Nicole</p>
<p>Und Dankeschön Werner. Du hast mir schon ein großes Stück weitergeholfen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2343562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2343562</guid><dc:creator><![CDATA[nickey1989]]></dc:creator><pubDate>Mon, 05 Aug 2013 12:34:24 GMT</pubDate></item><item><title><![CDATA[Reply to Einlesen einer Textdatei in eine Matrix on Mon, 05 Aug 2013 13:11:23 GMT]]></title><description><![CDATA[<p>nickey1989 schrieb:</p>
<blockquote>
<p>Die Zeile 12 verstehe ich jedoch nicht.</p>
</blockquote>
<p>Ein Stream (hier <code>ifstream</code> ) hat immer einen Zustand. Einfach gesagt: Entweder ist der Zustand des Streams<br />
- gut ==&gt; Die nachfolgende Operation, die du auf den Stream anwendest, könnte funktionieren.<br />
- oder schlecht ==&gt; Alle Operationen, die du auf den Stream anwendest, schlagen fehl.</p>
<p>Dein Format nutzt ja einen ; als Trennzeichen. Wenn das zu überlesende Zeichen ein ; ist, ist alles gut, das Format stimmt. Ist es aber kein ; dann ist ein Formatfehler aufgetreten. Wenn das passiert, sagen wir einfach, der Stream ist schrott und überführen (setstate) ihn deswegen in den Zustand schlecht (ios_base::fail). Somit verhindern wir weitere Operationen, da offensichtlich etwas nicht stimmt.</p>
<p>nickey1989 schrieb:</p>
<blockquote>
<p>Die Einteilung der Klasse in public und private verursacht bei mir Probleme. Es kommt die Fehlermeldung: Auf &quot;Member &quot;winddata::date&quot; (deklariert in Zeile 30)&quot; kann nicht zugegriffen werden. Deshalb habe ich das Schlüsselwort &quot;private&quot; gelöscht. Ich habe nun die gesamten Elemente der Klasse als &quot;public&quot; deklariert.</p>
</blockquote>
<p>Kann eigentlich nicht sein (da friend). Hast du den Quellcode von Werner wirklich kopiert?</p>
<p>nickey1989 schrieb:</p>
<blockquote>
<p>Ich habe dann ein Objekt winddata_object erzeugt, wie man im Code unten sehen kann. Ich wollte dann einzele Elemente dieses Objektes ausgeben lassen. Aber ich erhalte keine bzw. falsche Werte. Wo liegt mein Fehler?</p>
<pre><code>winddata winddata_object;
cout &lt;&lt; winddata_object.date &lt;&lt; endl;
cout &lt;&lt; winddata_object.lat &lt;&lt; endl;
</code></pre>
</blockquote>
<p>Na, du musst <code>winddata_object</code> ja erstmal einlesen. So hat es ja total willkürliche Werte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2343574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2343574</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Mon, 05 Aug 2013 13:11:23 GMT</pubDate></item></channel></rss>