Wartezeit in C++
-
Ich will gerne dass mein Programm eine gewisse Zeit wartet. Die Zeit wird vom Benutzer eingegeben. Ein anderes Programm kommt nicht in Frage, weil ich dann die ganzen Dateien im Order habe, und weil ich es nicht auf jedem Rechner neu installieren kann. Außerdem möchte ich verhindern, dass das cmd Fenster zu gemüllt wird. Wie zum Beispiel bei
ping -n "zeit" localhostIch verwende Dev-cpp und habe Windows 8.1
#include <iostream> using namespace std; int main () { int Stunden = 0; //Stunden die gewartet werden sollen int Minuten = 0; //Minuten die gewartet werden sollen int Sekunden = 0; //Sekunden die gewartet werden sollen cout << "Countdown: " << endl << endl; //Überschrift cout << "Anzahl der Stunden: "; //Text cin >> Stunden; //Benutzer soll Zeit in Stunden angeben cout << endl << endl; //Absatz cout << "Anzahl der Minuten: "; //Text cin >> Minuten; //Benutzer soll Zeit in Minuten angeben cout << endl << endl; //Absatz cout << "Anzahl der Sekunden: "; //Text cin >> Sekunden; //Benutzer soll Zeit in Sekunden angeben cout << endl << endl; //Absatz int Gesamt = (Sekunden * 1) + (Minuten * 60) + (Stunden * 3600); //Gesamtzeit die gewartet werden soll cout << "Es werden nun " << Gesamt << " Sekunden gewartet." << endl << endl;//Text //Hier soll die vom Benutzer angegebene (Gesamt)Zeit gewartet werden cout << "Es wurden " << Gesamt << " Sekunden gewartet." << endl << endl; //Text cin.get(); //Wartet bis Taste gedrückt wird return 0; }
-
#include <chrono> std::this_thread::sleep_for(std::chrono::seconds(3));
-
Aber bei deienr Ping Lösung kannst du auch vorher ein @echooff einstellen und dann wird dein CMD-Window nicht "zugemüllt".
Die Frage ist, was hast du vor?
-
Ist eigentlich nur ein Countdown. Aber wie kann ich in einer c++ datei den ping befehl ins cmd Fenster bringen? Und da is ja ne Variable drinnen.
und mit dem #include <chrono> kommt:
// Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file bits/c++0x_warning.h * This is an internal header file, included by other library headers. * Do not attempt to use it directly. @headername{iosfwd} */ #ifndef _CXX0X_WARNING_H #define _CXX0X_WARNING_H 1 #ifndef __GXX_EXPERIMENTAL_CXX0X__ #error This file requires compiler and library support for the \ ISO C++ 2011 standard. This support is currently experimental, and must be \ enabled with the -std=c++11 or -std=gnu++11 compiler options. #endif #endif
-
Steht doch alles in der Fehlermeldung:
This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
-
Ich weiß aber nicht wirklich was ich jetzt machen soll... Oder besser gesagt wie
-
Wenn du den Compiler in der CMD aufrufst, gibst du -std=c++11 an.
Wenn du eine IDE verwendest suchst du dir die Compilereinstellungen und gibst das dort an.
-
Funktioniert immer noch nicht. Und ich hab keine Ahnung warum. Hab alles probiert was ich im Inet gefunden hab und ihr mir gesagt habt...

-
Wie kompilierst und startest du das Programm denn?
-
Ich verwende Dev-cpp
Dazu habe ich gleich das hier gefunden:
http://www.cplusplus.com/doc/tutorial/introduction/devcpp/