C++ lernen, Beispiel: RPG (Console)
-
Nexus schrieb:
Hast du überprüft, ob deine g++-Version diese Features bereits unterstützt?
Wo seh ich meine g++ Version unter Windows?
Ich habe das aktuellste Code::Blocks mit MinGW installiert.Nexus schrieb:
Und du machst nicht sonst einen unnötigen Fehler, wie z.B. Namensraum
std
vergessen? Zeig mal kompletten minimalen Code.#include <iostream> #include <string> #include <cmath> #include <algorithm> #include <iomanip> #include <vector> #include <fstream> #include <cstdlib> #include <cstdio> #include <ctime> #include <conio.h> #include <unistd.h> #include <chrono> #include <thread> using namespace std; int main(){ sleep_for(1); return(0); }
-
Sollte eigentlich funktionieren, oder?
-
origami schrieb:
Sollte eigentlich funktionieren, oder?
Nein, sollte nicht funktionieren.
Sage mir in welchem Namespace sleep_for(..) dekl. ist und du findest raus, warum es nicht geht.Hier noch eine Hilfe:
http://en.cppreference.com/w/cpp/thread/sleep_for
-
origami schrieb:
Sollte eigentlich funktionieren, oder?
Nein.
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> using namespace std; int main(){ std::this_thread::sleep_for(std::chrono::seconds(1)); return ((0)); }
-
Ich mag dein dezentes return ((0)), viel besser als die ganzen Header.
-
-
theta schrieb:
Nein, sollte nicht funktionieren.
Sage mir in welchem Namespace sleep_for(..) dekl. ist und du findest raus, warum es nicht geht.Hier noch eine Hilfe:
http://en.cppreference.com/w/cpp/thread/sleep_forJetzt wo du´s sagst
Ist es möglich, mehrere namespaces zu nutzen, solange sich die Funktionen nicht überschneiden?
volkard schrieb:
Nein.
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> using namespace std; int main(){ std::this_thread::sleep_for(std::chrono::seconds(1)); return ((0)); }
-
origami schrieb:
Ist es möglich, mehrere namespaces zu nutzen, solange sich die Funktionen nicht überschneiden?
Du kannst mehrere namespaces nutzen, du kannst auch mehrere namespaces per using namespace ins Projekt holen, selbst wenn es Namenskollisionen gibt.
namespace A{ int bla; } namespace B{ double bla; } void foo(){ using namespace A; bla++; //geht } void blup(){ using namespace B; bla++; //geht } using namespace A; using namespace B; int main(){ bla++; //error: Welches bla? A::bla++; //geht B::bla++; //geht }
Solange es keine Kollisionen gibt kannst du alles per using rein holen, wenn es doch welche gibt sagt dir der Compiler bescheid und du must es ihm sagen.
Du solltest nur vermeiden per using sachen rein zu holen, die die entsprechende Datei gar nicht braucht. Aus diesem Grund sollte man kein using namespace global in den Header tun.
-
nwp3 schrieb:
Du kannst mehrere namespaces nutzen, du kannst auch mehrere namespaces per using namespace ins Projekt holen, selbst wenn es Namenskollisionen gibt.
namespace A{ int bla; } namespace B{ double bla; } void foo(){ using namespace A; bla++; //geht } void blup(){ using namespace B; bla++; //geht } using namespace A; using namespace B; int main(){ bla++; //error: Welches bla? A::bla++; //geht B::bla++; //geht }
Solange es keine Kollisionen gibt kannst du alles per using rein holen, wenn es doch welche gibt sagt dir der Compiler bescheid und du must es ihm sagen.
Du solltest nur vermeiden per using sachen rein zu holen, die die entsprechende Datei gar nicht braucht. Aus diesem Grund sollte man kein using namespace global in den Header tun.Super Beispiel, danke!
-
Bei Curses habe ich jetzt folgendes Problem:
Mein Held wandert auf Tastendruck über den Bildschirm, allerdings wenn ich eine Taste nicht nur drücke, sondern gedrückt halte, "hängt" die Ausgabe, sodass ich nicht sehe, wo der Held gerade ist.
Kennt jemand eine Lösung für dieses Problem?
-
origami schrieb:
Bei Curses habe ich jetzt folgendes Problem:
Mein Held wandert auf Tastendruck über den Bildschirm, allerdings wenn ich eine Taste nicht nur drücke, sondern gedrückt halte, "hängt" die Ausgabe, sodass ich nicht sehe, wo der Held gerade ist.
Kennt jemand eine Lösung für dieses Problem?
Auch wenn das Problem im Zusammenhang mit Deinem Lern-RPG-Projekt steht:
- neuer Thread, aussagekräftiger Titel.
- Richtiges Forum wählen: ein curses Problem hat nix mit C++ zu tun. Allerdings wüsste ich auch nicht wohin mit dem Thread. Dann also doch ins C++ Forum.
- Minimalbeispiel (compilierbar), dass das Problem veranschaulicht.
Siehe auch: Den richtigen Code posten: reduziertes compilierbares Beispiel
-
Funktioniert und kann closed
-
Danke an alle, die mir geholfen haben, die C++ Basics zu lernen.
Für alle, die es sich anschauen möchten, hier ist mein Lern-Spiel:
-
Anstatt eine exe hochzuladen, die eh keiner runterläd, weil es einfach viel zu gefährlich ist, könntest du doch deine source files bei github oder vergleichbarem uppen?