Code aus Buch "Learn C++ with Game Develoment" bringt Debugger Fehler. Warum?
-
Hier ist der Code aus dem Buch (https://www.pdfdrive.com/learn-c-for-game-development-e32342825.html):
#include <ctime>
#include <cstdlib> #include <iostream> #include <string>
using namespace std; int main()
{
// Generate unique random numbers using the current time srand(time(NULL));
// Get a random number between 0 and 99
unsigned int numberToGuess = rand() % 100; cout << "Guess a number between 0 and 99" << endl; unsigned int playersNumber {};
cin >> playersNumber;
cout << "You guessed: " << playersNumber << " The actual number was: " << numberToGuess << endl;
return 0; }I get following 1 Error message:
"#include <ctime>
#include <cstdlib> #include <iostream> #include <string>
using namespace std; int main()
{
// Generate unique random numbers using the current time srand(time(NULL));
// Get a random number between 0 and 99
unsigned int numberToGuess = rand() % 100; cout << "Guess a number between 0 and 99" << endl; unsigned int playersNumber {};
cin >> playersNumber;
cout << "You guessed: " << playersNumber << " The actual number was: " << numberToGuess << endl;
return 0; }"I tried to add the std:cout instead of only cout
"#include <ctime>
#include <cstdlib>
#include <iostream>
#include <string>//using namespace std;
int main()
{
std::cout << "hello";// Generate unique random numbers using the current time
std::srand(time(NULL));
// Get a random number between 0 and 99
unsigned int numberToGuess = rand() % 100;
std::cout << "static constructor\n";std::cout << "Guess a number between 0 and 99" << endl;
unsigned int playersNumber {};
std::cout >> playersNumber;
std::cout << "You guessed: " << playersNumber << " The actual number was: " << numberToGuess << endl;
return 0;
}"
and got only a black screen and no text.
Warum ist das wohl so?
Danke vorab?
-
Du hast den Fehler nicht gepostet, sondern nochmals deinen Code (und packe diesen in C++-Tags)...
-
endl
ist auchstd
.