Begriffe in C++ zusammenfassen
-
geschlossen
-
wisnia schrieb:
doch doch, kannst du ^^ in dem du mir zB sagst was ich hier falsch hab:
#include map<string,string> Kontinente;
landNachKontinent["Spanien"]="Europa";
landNachKontinent["Deutschland"]="Europa";
using namespace std;int main(int argc, char *argv[])
Schau dir als erstes an, wie man eine #include-Anwisung richtig schreibt. Als nächstes müsstest du dir überlegen, wie die std::map nun heißen soll. Bei diesem Namen bleibst du dann.
-
wisnia schrieb:
in dem du mir zB sagst was ich hier falsch hab
So ziemlich alles. So wird das nichts. Schnapp dir ein Buch oder Tutorial und lerne die Sprache, in der du programmieren willst. Drauf los programmieren klappt mit C++ nicht. Du musst lernen. Ansonsten kannst du es gleich lassen.

-
Ich dachte zunächst an set:
#include <iostream> #include <set> #include <string> int main() { using namespace std; set<string> europa = {"Spanien", "Deutschland", "Niederlande"}; string land = "Spanien"; cout << land << " ist "; if (europa.count(land)==0) { cout << "nicht "; } cout << "Teil von Europa.\n"; }
-
Und wenn man mehrere Kontinente hat?
Wird dann daraus ein std::vector<std::setstd::string>?
Oder glatt eine std::map<std::string, std::setstd::string>?
Da ist eine std::map<std::string, std::string> wesentlich einfacher...
-
Nathan schrieb:
Und wenn man mehrere Kontinente hat?
Und wenn ein Land in mehreren Kontinenten ist (Russland)?

-
Dann ignoriert man eben Russland oder verfrachtet es kurzerhand nach Asien! :p
Dann verwendet man eine Multimap.
Oder man bastelt sich einen eigenen Datentyp, der zwei Strings speichert, und dem man einen string zuweisen kann.
-
Jockelx schrieb:
Und wenn ein Land in mehreren Kontinenten ist (Russland)?

Auch Spanien liegt auch in mehreren Kontinenten Europa und Afrika.
Festland, Balearen: Europa
Kanarische Inseln, Ceuta , Melilla: Afrika
-
Jockelx schrieb:
Nathan schrieb:
Und wenn man mehrere Kontinente hat?
Und wenn ein Land in mehreren Kontinenten ist (Russland)?

Da sich für die paar Kontinente eh enums anbieten wollten,
EUROPA=1,ASIEN=2,AUSTRALIEN=4,... landNachKontinente["Russland"]=3;
-
Oder EUROPA | ASIEN.
Edit: Oder "Europa" | "Asien". |-Operator für Zeichenketten definieren!
Aber enums sind in diesem Fall wirklich besser:landNachKontinent["Spanien"] = "Europa"; //... if (landNachKontinent[land] == "Euorpa") // Upps, Tippfehler //...
-
Oder so.

#include <iostream> enum class Country { Germany, Austria, China }; template<Country... Members> struct CountryGroup { static bool contains(Country country) { bool result = false; bool dummy[] = { (result || (result = country == Members))... }; (void)dummy; return result; } }; typedef CountryGroup<Country::Germany, Country::Austria> Europe; typedef CountryGroup<Country::Germany, Country::China> NonDemocratic; int main() { std::cout << "Germany is "; if(!Europe::contains(Country::Germany)) std::cout << "not "; std::cout << "in Europe!\n"; std::cout << "China is "; if(!Europe::contains(Country::China)) std::cout << "not "; std::cout << "in Europe!\n"; }
-
geschlossen
-
geschlossen
-
Und in Europa.
-
geschlossen
-
Das ist C++11, Dev-C++ supported es höchstwahrscheinlich nicht.
-
wisnia schrieb:
doch doch, kannst du ^^ in dem du mir zB sagst was ich hier falsch hab:
#include map<string,string> Kontinente; landNachKontinent["Spanien"]="Europa"; landNachKontinent["Deutschland"]="Europa"; using namespace std;int main(int argc, char *argv[])
c++ Tags wären cool.
Unten unter dem Eingabe Feld auf C++ drücken dann Code rein dann wieder C++* drücken.#include map<string,string> Kontinente; //warum steht da ein include? landNachKontinent["Spanien"]="Europa"; //Warum heißt es plötzlich landNachKontinent?? landNachKontinent["Deutschland"]="Europa"; using namespace std;//warum kommt der namespace erst nach dem map? -> std::map
-
geschlossen
-
wisnia schrieb:
so funktioniert es jedenfalls auch nicht. Da kommt raus invalid preprocessing directive # map
schau nochmal in ein gutes Grundlagenbuch.
mit # erstellt man Präprozessordirektiven, keine globalen Variablen.
-
geschlossen