<?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[Strukturen übergeben &#x2F; String sortieren]]></title><description><![CDATA[<p>Hallöchen zusammen,</p>
<p>ich lerne derzeit C/C++ in der Schule und Teilweise zu Hause, normal schreibe ich in anderen Sprachen, allerdings habe ich nun ein kleines Problem:</p>
<p>Ich wollte eine Schulaufgabe noch et was weiter ausschmücken um ein wenig mehr mit C zu schreiben. Es soll eine Personaldatenverwaltung werden. Die normale Ausgabe funktioniert einwandfrei, allerdings funktioniert die Übergabe bei der sort_strings() Funktion nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /> Ich habe dort alles gleich gemacht, aber es will nicht funktionieren. Könnte mir das jemand vielleicht nochmal erläutern bzw. schauen ob ich einen Fehler im Script habe?</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;

using namespace std;

struct personaldaten {
       string name;
       string vorname;
       string geburtsdatum;
       char geschlecht;
       int personalnr;
};

void ausgabe(personaldaten *, int);

int main(int argc, char *argv[]){

    int iEingabe;
    int iAnzahldermitarbeiter = 3;
    int i;

    struct personaldaten mitarbeiter[iAnzahldermitarbeiter];

    cout &lt;&lt; &quot;Personaldaten-Verwaltung&quot; &lt;&lt; endl &lt;&lt; &quot;------------------------&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;1. Personaldaten eingeben&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2. Personaldaten importieren&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0. Beenden&quot; &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; &quot;Eingabe:&quot;;
    cin &gt;&gt; iEingabe;

    if (iEingabe == 1){       
       for (i = 0; i &lt; iAnzahldermitarbeiter; i++){
           system(&quot;cls&quot;);
           cout &lt;&lt; endl &lt;&lt; &quot;Namen des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].name;
           cout &lt;&lt; &quot;Vornamen des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].vorname;
           cout &lt;&lt; &quot;Geburtsdatum des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].geburtsdatum;
           cout &lt;&lt; &quot;Geschlecht des Mitarbeiters an (Maennlich = m / Weiblich = w):&quot;;
           cin &gt;&gt; mitarbeiter[i].geschlecht;
           cout &lt;&lt; &quot;Personalnummer des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].personalnr;
       }
    } else if (iEingabe == 2){
           // Hier werden spaeter Informationen importiert...
    } else if (iEingabe == 0){
           return 0;
    }

    system(&quot;cls&quot;);
    cout &lt;&lt; &quot;Personaldaten-Verwaltung&quot; &lt;&lt; endl &lt;&lt; &quot;------------------------&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;1. Personaldaten sortiert nach Name ausgeben&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2. Personaldaten sortiert nach Vorname&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3. Personaldaten sortiert nach Geburtsdatum&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4. Personaldaten sortiert nach Geschlecht&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;5. Personaldaten sortiert nach Personalnummer&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;6. Personaldaten unsortiert ausgeben&quot; &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; &quot;Eingabe:&quot;;
    cin &gt;&gt; iEingabe;
    system(&quot;cls&quot;);

    if (iEingabe == 1){
           sort_strings(mitarbeiter, iAnzahldermitarbeiter);
    } else if (iEingabe == 2){
           //FUNKTION
    } else if (iEingabe == 3){
           //FUNKTION
    } else if (iEingabe == 4){
           //FUNKTION
    } else if (iEingabe == 5){
           //FUNKTION
    } else if (iEingabe == 6){
           ausgabe(mitarbeiter, iAnzahldermitarbeiter);
    }

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

void ausgabe(personaldaten *mitarbeiter, int iAnzahldermitarbeiter){
     int i;

     cout &lt;&lt; &quot;Name - Vorname - Geburtsdatum - Geschlecht - Personalnummer&quot; &lt;&lt; endl;
     for (i = 0; i &lt; iAnzahldermitarbeiter; i++){
         cout &lt;&lt; mitarbeiter[i].name &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].vorname &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].geburtsdatum &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].geschlecht &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].personalnr &lt;&lt; endl;
     }
}

void sort_strings(personaldaten *mitarbeiter, int iAnzahldermitarbeiter){
	int i,j,n;
	char temp[iAnzahldermitarbeiter];

	cout &lt;&lt; mitarbeiter[0].name;

}
</code></pre>
<p>Ich habe mir einige Varianten bei Google angeschaut allerdings ist der Groschen leider nicht gefallen ... alle meine Versuche mit strcmp() sind gescheitert weil er wohl eine Const verlangt ...</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313940/strukturen-übergeben-string-sortieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 17:46:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313940.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Feb 2013 20:39:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Thu, 14 Feb 2013 20:39:45 GMT]]></title><description><![CDATA[<p>Hallöchen zusammen,</p>
<p>ich lerne derzeit C/C++ in der Schule und Teilweise zu Hause, normal schreibe ich in anderen Sprachen, allerdings habe ich nun ein kleines Problem:</p>
<p>Ich wollte eine Schulaufgabe noch et was weiter ausschmücken um ein wenig mehr mit C zu schreiben. Es soll eine Personaldatenverwaltung werden. Die normale Ausgabe funktioniert einwandfrei, allerdings funktioniert die Übergabe bei der sort_strings() Funktion nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /> Ich habe dort alles gleich gemacht, aber es will nicht funktionieren. Könnte mir das jemand vielleicht nochmal erläutern bzw. schauen ob ich einen Fehler im Script habe?</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;

using namespace std;

struct personaldaten {
       string name;
       string vorname;
       string geburtsdatum;
       char geschlecht;
       int personalnr;
};

void ausgabe(personaldaten *, int);

int main(int argc, char *argv[]){

    int iEingabe;
    int iAnzahldermitarbeiter = 3;
    int i;

    struct personaldaten mitarbeiter[iAnzahldermitarbeiter];

    cout &lt;&lt; &quot;Personaldaten-Verwaltung&quot; &lt;&lt; endl &lt;&lt; &quot;------------------------&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;1. Personaldaten eingeben&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2. Personaldaten importieren&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0. Beenden&quot; &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; &quot;Eingabe:&quot;;
    cin &gt;&gt; iEingabe;

    if (iEingabe == 1){       
       for (i = 0; i &lt; iAnzahldermitarbeiter; i++){
           system(&quot;cls&quot;);
           cout &lt;&lt; endl &lt;&lt; &quot;Namen des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].name;
           cout &lt;&lt; &quot;Vornamen des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].vorname;
           cout &lt;&lt; &quot;Geburtsdatum des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].geburtsdatum;
           cout &lt;&lt; &quot;Geschlecht des Mitarbeiters an (Maennlich = m / Weiblich = w):&quot;;
           cin &gt;&gt; mitarbeiter[i].geschlecht;
           cout &lt;&lt; &quot;Personalnummer des Mitarbeiters an:&quot;;
           cin &gt;&gt; mitarbeiter[i].personalnr;
       }
    } else if (iEingabe == 2){
           // Hier werden spaeter Informationen importiert...
    } else if (iEingabe == 0){
           return 0;
    }

    system(&quot;cls&quot;);
    cout &lt;&lt; &quot;Personaldaten-Verwaltung&quot; &lt;&lt; endl &lt;&lt; &quot;------------------------&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;1. Personaldaten sortiert nach Name ausgeben&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2. Personaldaten sortiert nach Vorname&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3. Personaldaten sortiert nach Geburtsdatum&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4. Personaldaten sortiert nach Geschlecht&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;5. Personaldaten sortiert nach Personalnummer&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;6. Personaldaten unsortiert ausgeben&quot; &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; &quot;Eingabe:&quot;;
    cin &gt;&gt; iEingabe;
    system(&quot;cls&quot;);

    if (iEingabe == 1){
           sort_strings(mitarbeiter, iAnzahldermitarbeiter);
    } else if (iEingabe == 2){
           //FUNKTION
    } else if (iEingabe == 3){
           //FUNKTION
    } else if (iEingabe == 4){
           //FUNKTION
    } else if (iEingabe == 5){
           //FUNKTION
    } else if (iEingabe == 6){
           ausgabe(mitarbeiter, iAnzahldermitarbeiter);
    }

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

void ausgabe(personaldaten *mitarbeiter, int iAnzahldermitarbeiter){
     int i;

     cout &lt;&lt; &quot;Name - Vorname - Geburtsdatum - Geschlecht - Personalnummer&quot; &lt;&lt; endl;
     for (i = 0; i &lt; iAnzahldermitarbeiter; i++){
         cout &lt;&lt; mitarbeiter[i].name &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].vorname &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].geburtsdatum &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].geschlecht &lt;&lt; &quot; - &quot; &lt;&lt; mitarbeiter[i].personalnr &lt;&lt; endl;
     }
}

void sort_strings(personaldaten *mitarbeiter, int iAnzahldermitarbeiter){
	int i,j,n;
	char temp[iAnzahldermitarbeiter];

	cout &lt;&lt; mitarbeiter[0].name;

}
</code></pre>
<p>Ich habe mir einige Varianten bei Google angeschaut allerdings ist der Groschen leider nicht gefallen ... alle meine Versuche mit strcmp() sind gescheitert weil er wohl eine Const verlangt ...</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2298956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2298956</guid><dc:creator><![CDATA[YaeroxXO]]></dc:creator><pubDate>Thu, 14 Feb 2013 20:39:45 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Thu, 14 Feb 2013 20:53:15 GMT]]></title><description><![CDATA[<p>Nicht die Übergabe ist das Problem, sondern die Funktionsdefinition selbst. Die Funktion macht nämlich nichts, weil da der ganze rest noch fehlt. Wozu hast du die Vaariablen i, j, etc.? Was soll es für eine Sortierung sein? Alphabetische? Du siehst wahrscheinlich selbst, dass du in der Funktion dein Array nicht anfasst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2298960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2298960</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Thu, 14 Feb 2013 20:53:15 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Fri, 15 Feb 2013 06:56:54 GMT]]></title><description><![CDATA[<blockquote>
<p>[...] um ein wenig mehr mit C zu schreiben.</p>
</blockquote>
<p>Man merkt's.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2298996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2298996</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 15 Feb 2013 06:56:54 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Fri, 15 Feb 2013 09:23:28 GMT]]></title><description><![CDATA[<p>Ich nehme an mit &quot;es will nicht funktionieren&quot; meinst du, dass das Programm nicht kompiliert. Du brauchst einen Prototypen fuer die Funktion sort_string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299017</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299017</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Fri, 15 Feb 2013 09:23:28 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Fri, 15 Feb 2013 10:43:03 GMT]]></title><description><![CDATA[<p>Willst du C oder C++ schreiben? Der Code ist ein ziemlicher Mischmasch aus beidem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299026</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Fri, 15 Feb 2013 10:43:03 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Fri, 15 Feb 2013 17:29:35 GMT]]></title><description><![CDATA[<p>[Rewind] schrieb:</p>
<blockquote>
<p>Nicht die Übergabe ist das Problem, sondern die Funktionsdefinition selbst. Die Funktion macht nämlich nichts, weil da der ganze rest noch fehlt.</p>
</blockquote>
<p>Ich habe den Funktionsprototypen scheinbar vergessen, und ja es fehlt noch ein Teil der Funktion.</p>
<p>[Rewind] schrieb:</p>
<blockquote>
<p>Wozu hast du die Vaariablen i, j, etc.? Was soll es für eine Sortierung sein? Alphabetische? Du siehst wahrscheinlich selbst, dass du in der Funktion dein Array nicht anfasst.</p>
</blockquote>
<p>Die Variablen sollten für folgende Schleifen sein. Die Sortierung habe ich vielleicht nicht genau erklärt, sry. Ich möchte gerne Strings Lexikografisch/Alphabetisch sortieren.</p>
<p>Sone schrieb:</p>
<blockquote>
<blockquote>
<p>[...] um ein wenig mehr mit C zu schreiben.</p>
</blockquote>
<p>Man merkt's.</p>
</blockquote>
<p>Was soll ich dir antworten ...</p>
<p>icarus2 schrieb:</p>
<blockquote>
<p>Ich nehme an mit &quot;es will nicht funktionieren&quot; meinst du, dass das Programm nicht kompiliert. Du brauchst einen Prototypen fuer die Funktion sort_string.</p>
</blockquote>
<p>Habe ich bemerkt, dank dir.</p>
<p>daddy_felix schrieb:</p>
<blockquote>
<p>Willst du C oder C++ schreiben? Der Code ist ein ziemlicher Mischmasch aus beidem.</p>
</blockquote>
<p>Ich muss ehrlich gestehen, ich kenne kaum einen unterschied zwischen C und C++. Ich schreibe normal in/mit anderen Sprachen nur in der Schule machen wir nun C/C++, wir können beides nehmen und uns wurde bisher nicht viel darüber erzählt. Ich denke ich werde das noch nachholen, aber soweit ist es also egal was ich verwende.</p>
<p>Schonmal vielen Dank für die Antworten, komme grad erst von der Arbeit dass ich hier rein schauen konnte und werde am Wochenende wieder am Script schreiben und mich nochmal melden wenn ich weiter bin.</p>
<p>Grüße YaeroxXO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299163</guid><dc:creator><![CDATA[Yaerox]]></dc:creator><pubDate>Fri, 15 Feb 2013 17:29:35 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 15:26:17 GMT]]></title><description><![CDATA[<p>Ich hätte nochmal eine Frage bezüglich Structs. Ich habe nun eine Funktion zum sortieren von Strings, jedoch würde ich jetzt gerne noch ein Feature einbauen:</p>
<pre><code>void sort_strings(personaldaten *mitarbeiter, int iAnzahldermitarbeiter){
    bool aenderungGemacht;
    do {
	    aenderungGemacht = false;
	    for (int i=0; i&lt;(iAnzahldermitarbeiter-1); i++){
		    if (stricmp(mitarbeiter[i].name.c_str(), mitarbeiter[i+1].name.c_str())&gt;0){
			    personaldaten tmp = mitarbeiter[i];
			    mitarbeiter[i] = mitarbeiter[i+1];
			    mitarbeiter[i+1] = tmp;
			    aenderungGemacht = true;
		    }
	    }
    } while (aenderungGemacht);
}
</code></pre>
<p>besteht nicht die Möglichkeit, dass ich einen 3ten Parameter übergebe und in diesem Fall statt nach Name auch nach Vorname, Personalnummer etc. sortieren kann?</p>
<p>Er sagt mir jedesmal dass das Attribut kein Teil des structs ist...<br />
[/code]void sort_strings(personaldaten *mitarbeiter, int iAnzahldermitarbeiter, string attribut){<br />
bool aenderungGemacht;<br />
do {<br />
aenderungGemacht = false;<br />
for (int i=0; i&lt;(iAnzahldermitarbeiter-1); i++){<br />
if (stricmp(mitarbeiter[i].attribut.c_str(), mitarbeiter[i+1].attribut.c_str())&gt;0){<br />
personaldaten tmp = mitarbeiter[i];<br />
mitarbeiter[i] = mitarbeiter[i+1];<br />
mitarbeiter[i+1] = tmp;<br />
aenderungGemacht = true;<br />
}<br />
}<br />
} while (aenderungGemacht);<br />
}[/code]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299261</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299261</guid><dc:creator><![CDATA[YaeroxXO]]></dc:creator><pubDate>Sat, 16 Feb 2013 15:26:17 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 19:24:40 GMT]]></title><description><![CDATA[<p>YaeroxXO schrieb:</p>
<blockquote>
<p>Er sagt mir jedesmal dass das Attribut kein Teil des structs ist...</p>
</blockquote>
<p>Er (der Compiler) hat immer recht.<br />
Dein struct hat kein Attribut namens attribut. Oder siehst du irgendwo eins?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299291</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Sat, 16 Feb 2013 19:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 18:15:40 GMT]]></title><description><![CDATA[<p>Weil du nicht einfach strings nach Code konvertieren kannst!<br />
Das geht in JavaScript aber nicht in C++.<br />
Entweder du nutzt Switch-Case und enums:</p>
<pre><code>enum howtosort{FIRSTNAME, LASTNAME,...)
void sort(..., howtosort howto)
{
    ...
    switch(howto)
    {
        case FIRSTNAME:
            if (strcmp(foo.firstname, ...))
                ...;
        case LASTNAME:
            if (strcmp(foo.lastname, ...))
                ...;
    }
}
</code></pre>
<p>Oder du übergibst einen Funktionszeiger an eine Funktion die das entscheidet:</p>
<pre><code>enum howtosort{FIRSTNAME, LASTNAME,...)
void sort(..., howtosort howto)
{
    ...
    switch(howto)
    {
        case FIRSTNAME:
            if (strcmp(foo.firstname, ...))
                ...;
        case LASTNAME:
            if (strcmp(foo.lastname, ...))
                ...;
    }
}
</code></pre>
<p>Was soll eigentlich dieses Mischen von C und C++?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299293</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 16 Feb 2013 18:15:40 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 18:43:18 GMT]]></title><description><![CDATA[<p>YaeroxXO schrieb:</p>
<blockquote>
<p>besteht nicht die Möglichkeit, dass ich einen 3ten Parameter übergebe und in diesem Fall statt nach Name auch nach Vorname, Personalnummer etc. sortieren kann?</p>
</blockquote>
<p>Das einleuchtendste ist wahrscheinlich eine Variante, die <code>switch</code> ed - siehe Nathans Antwort.<br />
Eine weitere - etwas kompaktere - Möglichkeit wäre einen Pointer auf das Attribut zu übergeben.</p>
<p>Vollständiges Beispiel (C++11!) mit hoffentlich noch ein paar Anregungen für Deine C++ Karriere:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;iomanip&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

struct personaldaten {
       std::string name;
       std::string vorname;
       std::string geburtsdatum;
       char geschlecht;
       int personalnr;
};

// personaldaten ausgeben
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const personaldaten&amp; p){
  os &lt;&lt; std::setw(5) &lt;&lt; p.personalnr &lt;&lt; &quot;: &quot; &lt;&lt; p.name &lt;&lt; &quot;, &quot; &lt;&lt; p.vorname
     &lt;&lt; ' ' &lt;&lt; p.geburtsdatum &lt;&lt; &quot; (&quot; &lt;&lt; p.geschlecht &lt;&lt; ')';
  return os;
}

// personaldaten nach Attribut sortieren
template&lt;typename RandomIter, typename Attr&gt;
void sort(RandomIter first, RandomIter last, Attr personaldaten::*a){
  std::sort(first, last, [a](const personaldaten&amp; x, const personaldaten&amp; y){
    return x.*a &lt; y.*a; });
}

int main(){
  using namespace std;
  typedef vector&lt;personaldaten&gt; personalliste;
  personalliste l = {
    {&quot;Mueller&quot;, &quot;Franz&quot;, &quot;01.01.2013&quot;, 'm', 123},
    {&quot;Moeller&quot;, &quot;Frank&quot;, &quot;01.01.2012&quot;, 'm', 125},
    {&quot;Mueller&quot;, &quot;Maria&quot;, &quot;01.01.2013&quot;, 'w', 124},
    {&quot;Schmidt&quot;, &quot;Julia&quot;, &quot;01.01.2013&quot;, 'w', 126}
  };
  sort(begin(l), end(l), &amp;personaldaten::personalnr);
  cout &lt;&lt; &quot;Nach Personalnummer:\n&quot;;
  for(auto p : l)
    cout &lt;&lt; p &lt;&lt; '\n';
  sort(begin(l), end(l), &amp;personaldaten::name);
  cout &lt;&lt; &quot;Nach Nachname:\n&quot;;
  for(auto p : l)
    cout &lt;&lt; p &lt;&lt; '\n';
}
</code></pre>
<p>Glückauf!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299304</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Sat, 16 Feb 2013 18:43:18 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Thu, 12 Jun 2014 10:52:56 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299306</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 12 Jun 2014 10:52:56 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 20:24:14 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Oder du übergibst einen Funktionszeiger an eine Funktion die das entscheidet:</p>
<pre><code>enum howtosort{FIRSTNAME, LASTNAME,...)
void sort(..., howtosort howto)
{
    ...
    switch(howto)
    {
        case FIRSTNAME:
            if (strcmp(foo.firstname, ...))
                ...;
        case LASTNAME:
            if (strcmp(foo.lastname, ...))
                ...;
    }
}
</code></pre>
</blockquote>
<p>Na das wirkt doch sehr gekünstelt, wo ist hier ein Funktionszeiger?<br />
Besser man nutzt das enum-Element direkt aus und spart dadurch ggü. der Ausgangsvariante wirklich Code:</p>
<pre><code>struct personaldaten {
       string name[3];
       char geschlecht;
       int personalnr;
};
void sort(..., howtosort howto)
{
            if (strcmp(foo.name[howto], ...))
                ...;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299310</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Sat, 16 Feb 2013 20:24:14 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Sat, 16 Feb 2013 20:50:22 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8250">@Swordfish</a>:<br />
Wo ist das Problem?<br />
Der TE kannte schon Pointer, also dachte ich, dass er das auch schon kann/nicht schwierig wird es zu verstehen.<br />
Oder meinst du was anderes?</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/24273">@Wutz</a>:<br />
Ja, das ist simpler.<br />
Aber falls er nach Geschlecht oder Alter sortieren will, fällt das weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299322</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 16 Feb 2013 20:50:22 GMT</pubDate></item><item><title><![CDATA[Reply to Strukturen übergeben &#x2F; String sortieren on Thu, 12 Jun 2014 10:53:04 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299372</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 12 Jun 2014 10:53:04 GMT</pubDate></item></channel></rss>