<?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[std::string, stringstream... Tschuldigung blick nicht durch]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>erst mal hallo, bin Mechatronikstudent und lerne im Zuge des Faches &quot;Softwareentwicklung&quot; C++. Bin Anfänger und komm weitestgehend mit Lektüre in Form von Büchern sowie (leider ehr weniger) Unterlagen zu den Vorlesungen durch.</p>
<p>In der ersten Übungsaufgabe sollen wir Komplexe Zahlen mit hilfe einer Klasse später auch mit Overloading verrechnen. Das Programm an sich ist nicht so das Problem leider steht in der Aufgabenstellung die Methode</p>
<pre><code>std::string toStr();
</code></pre>
<p>...womit wir auch schon beim Problem sind.</p>
<p>Ich schreib euch einfach mal den Quellcode hier rein:</p>
<pre><code>main.cpp
#include &lt;iostream&gt;
#include &quot;KomplexeZahl.h&quot;

using namespace std;

int main()
{
    KomplexeZahl* z1=new KomplexeZahl(23,15);
    KomplexeZahl* z2=new KomplexeZahl(45,3);    

    cout&lt;&lt;&quot;Meine erste Zahl ist:&quot;&lt;&lt;z1-&gt;toStr()&lt;&lt;endl;    
    cout&lt;&lt;&quot;Meine zweite Zahl ist:&quot;&lt;&lt;z2-&gt;toStr()&lt;&lt;endl;

    cout&lt;&lt;&quot;Meine Summe ist:&quot;&lt;&lt;z1-&gt;addiere(z2)-&gt;toStr()&lt;&lt;endl;
    cout&lt;&lt;&quot;Meine Quotient ist:&quot;&lt;&lt;z1-&gt;subtrahiere(z2)-&gt;toStr()&lt;&lt;endl;

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}

KomplexeZahl.h
class KomplexeZahl{
public:

KomplexeZahl(double real, double imag); // Konstruktor

std::string toStr(); // Wandelt die komplexe Zahl in einen String um z.B. (23 + 42i)

double getReal() const;
double getImag() const;

KomplexeZahl* addiere(KomplexeZahl* summand);
KomplexeZahl* subtrahiere(KomplexeZahl* subtrahend);

private:
double real;
double imag;
};

KomplexeZahl.cpp
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &quot;KomplexeZahl.h&quot;

KomplexeZahl::KomplexeZahl(double real, double imag){
       this-&gt;real=real;                 
       this-&gt;imag=imag;}                                 

std::string KomplexeZahl::toStr(){
       std::stringstream ausgabe;
       ausgabe&lt;&lt;&quot;(&quot;&lt;&lt;real&lt;&lt;&quot;+&quot;&lt;&lt;imag&lt;&lt;&quot;i)&quot;; 
       return ausgabe.str();} 

double KomplexeZahl::getReal() const{
       return real;}      

double KomplexeZahl::getImag() const{
       return imag;}      

KomplexeZahl* KomplexeZahl::addiere(KomplexeZahl* summand){
       double _real,_imag;
       _real=real+summand-&gt;getReal();
       _imag=imag+summand-&gt;getImag();
       return new KomplexeZahl(_real,_imag);}          

KomplexeZahl* KomplexeZahl::subtrahiere(KomplexeZahl* subtrahend){
       double _real,_imag;
       _real=real-subtrahend-&gt;getReal();
       _imag=imag-subtrahend-&gt;getImag();
       return new KomplexeZahl(_real,_imag);}
</code></pre>
<p>Hoffe is Ok wenn ich das hier so reinposte. Bitte erklär mir mal jemand die Zeile 50 bis 53 in allgemeiner Form in einfachen Worten ggf. auch en Lektürentipp hab da aber noch nicht sorecht was für mich gefunden.</p>
<p>LG Manu</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313063/std-string-stringstream-tschuldigung-blick-nicht-durch</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 11:01:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313063.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 Jan 2013 20:27:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Sun, 20 Jan 2013 20:27:50 GMT]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>erst mal hallo, bin Mechatronikstudent und lerne im Zuge des Faches &quot;Softwareentwicklung&quot; C++. Bin Anfänger und komm weitestgehend mit Lektüre in Form von Büchern sowie (leider ehr weniger) Unterlagen zu den Vorlesungen durch.</p>
<p>In der ersten Übungsaufgabe sollen wir Komplexe Zahlen mit hilfe einer Klasse später auch mit Overloading verrechnen. Das Programm an sich ist nicht so das Problem leider steht in der Aufgabenstellung die Methode</p>
<pre><code>std::string toStr();
</code></pre>
<p>...womit wir auch schon beim Problem sind.</p>
<p>Ich schreib euch einfach mal den Quellcode hier rein:</p>
<pre><code>main.cpp
#include &lt;iostream&gt;
#include &quot;KomplexeZahl.h&quot;

using namespace std;

int main()
{
    KomplexeZahl* z1=new KomplexeZahl(23,15);
    KomplexeZahl* z2=new KomplexeZahl(45,3);    

    cout&lt;&lt;&quot;Meine erste Zahl ist:&quot;&lt;&lt;z1-&gt;toStr()&lt;&lt;endl;    
    cout&lt;&lt;&quot;Meine zweite Zahl ist:&quot;&lt;&lt;z2-&gt;toStr()&lt;&lt;endl;

    cout&lt;&lt;&quot;Meine Summe ist:&quot;&lt;&lt;z1-&gt;addiere(z2)-&gt;toStr()&lt;&lt;endl;
    cout&lt;&lt;&quot;Meine Quotient ist:&quot;&lt;&lt;z1-&gt;subtrahiere(z2)-&gt;toStr()&lt;&lt;endl;

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}

KomplexeZahl.h
class KomplexeZahl{
public:

KomplexeZahl(double real, double imag); // Konstruktor

std::string toStr(); // Wandelt die komplexe Zahl in einen String um z.B. (23 + 42i)

double getReal() const;
double getImag() const;

KomplexeZahl* addiere(KomplexeZahl* summand);
KomplexeZahl* subtrahiere(KomplexeZahl* subtrahend);

private:
double real;
double imag;
};

KomplexeZahl.cpp
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &quot;KomplexeZahl.h&quot;

KomplexeZahl::KomplexeZahl(double real, double imag){
       this-&gt;real=real;                 
       this-&gt;imag=imag;}                                 

std::string KomplexeZahl::toStr(){
       std::stringstream ausgabe;
       ausgabe&lt;&lt;&quot;(&quot;&lt;&lt;real&lt;&lt;&quot;+&quot;&lt;&lt;imag&lt;&lt;&quot;i)&quot;; 
       return ausgabe.str();} 

double KomplexeZahl::getReal() const{
       return real;}      

double KomplexeZahl::getImag() const{
       return imag;}      

KomplexeZahl* KomplexeZahl::addiere(KomplexeZahl* summand){
       double _real,_imag;
       _real=real+summand-&gt;getReal();
       _imag=imag+summand-&gt;getImag();
       return new KomplexeZahl(_real,_imag);}          

KomplexeZahl* KomplexeZahl::subtrahiere(KomplexeZahl* subtrahend){
       double _real,_imag;
       _real=real-subtrahend-&gt;getReal();
       _imag=imag-subtrahend-&gt;getImag();
       return new KomplexeZahl(_real,_imag);}
</code></pre>
<p>Hoffe is Ok wenn ich das hier so reinposte. Bitte erklär mir mal jemand die Zeile 50 bis 53 in allgemeiner Form in einfachen Worten ggf. auch en Lektürentipp hab da aber noch nicht sorecht was für mich gefunden.</p>
<p>LG Manu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291748</guid><dc:creator><![CDATA[glückspirat]]></dc:creator><pubDate>Sun, 20 Jan 2013 20:27:50 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Sun, 20 Jan 2013 20:36:25 GMT]]></title><description><![CDATA[<p>Ein Stringstream ist im Prinzip so etwas wie ein normaler Ausgabestream. Mithilfe &lt;&lt; &quot;sendest&quot; du dort Strings, Integer, Klassen, die diesen Operator überladen haben, etc. an die Konsole und diese werden dort ausgegeben.<br />
Bei einem Stringstream werden diese &quot;Sachen&quot; nicht ausgegeben, sondern in einem String gespeichert. Diesen kannst du mit str() erhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291749</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 20 Jan 2013 20:36:25 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Sun, 20 Jan 2013 20:48:48 GMT]]></title><description><![CDATA[<p>Du brauchst übrigens nirgends new. Gewöhn dir am besten gleich ab, alle Objekte mit new zu erstellen. Diese musst du nämlich jeweils mit delete freigeben.</p>
<p>Schreib deine Funktionen so:</p>
<pre><code>KomplexeZahl KomplexeZahl::addiere(KomplexeZahl summand)
{
       double _real = real + summand.getReal();
       double _imag = imag + summand.getImag();
       return KomplexeZahl(_real,_imag);
}
</code></pre>
<p>Noch besser als freie Funktion (wenn nicht gleich Operator):</p>
<pre><code>KomplexeZahl addiere(KomplexeZahl links, KomplexeZahl rechts)
{
       double _real = links.getReal() + rechts.getReal();
       double _imag = links.getImag() + rechts.getImag();
       return KomplexeZahl(_real,_imag);
}
</code></pre>
<p>&lt;<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    />&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291751</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291751</guid><dc:creator><![CDATA[glühbirne]]></dc:creator><pubDate>Sun, 20 Jan 2013 20:48:48 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Sun, 20 Jan 2013 20:58:48 GMT]]></title><description><![CDATA[<p>Noch ein paar Anmerkungen zu deinem Code:</p>
<ul>
<li>Du legst die KomplexeZahl-Objekte im Freispeier an. Wieso? Machst du das auch so bei lokalen ints und doubles? Ich hoffe nicht.</li>
<li>Ich hoffe, KomplexeZahl.h enthält Include-Guards und die entsprechende Include-Direktive für std::string</li>
<li>Die Formatierung ist hässlich</li>
<li>Mach Dich mal zum Thema Initialisierungsliste bzgl Konstruktoren schlau</li>
<li>addiere und subtrahiere erzeugen wieder Objekte im Freispeicher. Das ist großer Käse.</li>
</ul>
<p>Es sieht so aus, als ob du Python in C++ programmieren würdest. Mach doch lieber &quot;richtiges&quot; C++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291752</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 20 Jan 2013 20:58:48 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Sun, 20 Jan 2013 21:44:54 GMT]]></title><description><![CDATA[<p>Hallo glückspirat,</p>
<p>schau Dir auch noch diesen <a href="http://www.c-plusplus.net/forum/312538" rel="nofollow">Thread über Komplexe Zahlen</a> an.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291760</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sun, 20 Jan 2013 21:44:54 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Tue, 22 Jan 2013 18:54:52 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>erst mal danke für die schnellen antworten.</p>
<p>danke vor allem für den link ist en kommilitone von mir wir ham zusammen softwareentwicklung und schreiben in 3 Wochen prüfung.</p>
<p>Falls es euch interessiert kann ich euch mal die komplette aufgabenstellung schicken mit den vorgegeben klassen damit ihr sehen könnt warum ich was mache mit Objekte mit new anlegen usw.</p>
<p>Könnte mir mal jemand die Zeilen:</p>
<pre><code>std::string KomplexeZahl::toStr(){
       std::stringstream ausgabe;
       ausgabe&lt;&lt;&quot;(&quot;&lt;&lt;real&lt;&lt;&quot;+&quot;&lt;&lt;imag&lt;&lt;&quot;i)&quot;;
       return ausgabe.str();}
</code></pre>
<p>mal mit einfachen worten erklären</p>
<p>Edit: Ach ja tschuldiugn für den hässlischen code</p>
<p>und weil ich heute verstreut bin Edit2: Die Aufgabenstellugn:<br />
<a href="https://www.dropbox.com/s/hoalmord9s2t0w3/Punkte%C3%9Cbungen-29.11.12.pdf" rel="nofollow">https://www.dropbox.com/s/hoalmord9s2t0w3/PunkteÜbungen-29.11.12.pdf</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292412</guid><dc:creator><![CDATA[glückspirat]]></dc:creator><pubDate>Tue, 22 Jan 2013 18:54:52 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Tue, 22 Jan 2013 19:00:49 GMT]]></title><description><![CDATA[<p>Zitat aus der Aufgabenstellung:</p>
<pre><code>KomplexeZahl* a = new KomplexeZahl(23.42, 42.23);
KomplexeZahl* b = new KomplexeZahl(42.23, 23.42);
KomplexeZahl* c = *a + *b;
cout &lt;&lt; a-&gt;toStr() &lt;&lt; &quot; + &quot; &lt;&lt; b-&gt;toStr() &lt;&lt; &quot; = &quot; &lt;&lt; c-&gt;toStr() &lt;&lt; endl;
</code></pre>
<p>Und sowas nennt sich Professor und lehrt C++ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292420</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292420</guid><dc:creator><![CDATA[Cyres]]></dc:creator><pubDate>Tue, 22 Jan 2013 19:00:49 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Tue, 22 Jan 2013 19:13:13 GMT]]></title><description><![CDATA[<p>@TE: Schaue dir mal meinen Post weiter oben an, vielleicht hilft der.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292427</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 22 Jan 2013 19:13:13 GMT</pubDate></item><item><title><![CDATA[Reply to std::string, stringstream... Tschuldigung blick nicht durch on Wed, 23 Jan 2013 13:46:13 GMT]]></title><description><![CDATA[<p>Cyres schrieb:</p>
<blockquote>
<p>Zitat aus der Aufgabenstellung:</p>
<pre><code>KomplexeZahl* a = new KomplexeZahl(23.42, 42.23);
KomplexeZahl* b = new KomplexeZahl(42.23, 23.42);
KomplexeZahl* c = *a + *b;
cout &lt;&lt; a-&gt;toStr() &lt;&lt; &quot; + &quot; &lt;&lt; b-&gt;toStr() &lt;&lt; &quot; = &quot; &lt;&lt; c-&gt;toStr() &lt;&lt; endl;
</code></pre>
<p>Und sowas nennt sich Professor und lehrt C++ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Warscheinlich durch Java durcheinandergekommen. Warum sollte ein Professor C++ können müssen?<br />
War vermutlich eine Idee der Uni C++ zu lehren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292619</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Wed, 23 Jan 2013 13:46:13 GMT</pubDate></item></channel></rss>