Hi,
This is small c++ guess game, I almost finished it, but when i tried compile it gave me an error: "Cannot open include file: 'stdlib': No such file or directory"
is this file part of c++ standard library..? why compiler can't find it?

here is my .cpp source:

Dani AI

Generated

As 's compile error indicates, the immediate symptom was an incorrect include name (see ). A concise, portable rule for C++: prefer the C++ wrapper headers (for example, use <cstdlib> rather than relying on a plain C header name), and qualify C functions with std:: when using the C++ headers. Some compilers make C names available in the global namespace, but portable code should not rely on that.

A minimal, robust pattern for simple random-number games is shown below. It uses the C++ headers and seeds the generator with the current time:

#include <cstdlib>
#include <ctime>
#include <iostream>

int main() {
    std::srand(static_cast<unsigned>(std::time(nullptr)));
    int secret = std::rand() % 100 + 1;
    std::cout << "Secret: " << secret << '\n';
}

conio.h and functions such as clrscr() / getch() are non-standard. They may exist in some Windows toolchains but reduce portability and can hide input/flush issues. For simple console interaction prefer standard facilities (std::getline, std::cin.get()), and for more control use a proven console library (ncurses / PDCurses) rather than vendor-specific headers.

For user-response handling (the play-again prompt), use std::string and std::getline to avoid leftover-newline problems; check the first character for 'y'/'Y' rather than reading a single char. Finally, if a correct header name still fails to be found, verify that the source file has a .cpp extension, the project is configured to build as C++, and the compiler include paths in the IDE are intact — missing headers can indicate a misconfigured toolchain rather than bad code.

Recommended Answers

All 5 Replies

stdlib.h you forgot the .h :]

is stdlib a header, or do you use cstdlib?

Thanks FrozenSnake, code worked well ..
what is header conio.h, is it important in c++ 2008 express

Thanks FrozenSnake, code worked well ..
what is header conio.h, is it important in c++ 2008 express

I have never used conio.h in any IDE's I used. If you want to read about it you can read here:
http://en.wikipedia.org/wiki/Conio.h

Hi,
This is small c++ guess game, I almost finished it, but when i tried compile it gave me an error: "Cannot open include file: 'stdlib': No such file or directory"
is this file part of c++ standard library..? why compiler can't find it?

here is my .cpp source:

Ok lets fix the first issue, in order to get stdlib to work add a .h to the end of it (i.e. #include <stdlib.h>)

Secondly your formatting is horrible. Your cout's are all done incorrectly, you have functions that are inproper such as line 51: that is an invalid line of code, as is line 19 and line 22 (well the { is valid, the clrscr() is not (nor is it necessary).

Lastly aside from sentence structures, your last while statement is improper, first change the char ans to string ans (don't forget to add the string header to the top), and then the while statement should be (ans == "y" || ans == "Y"). Also you need to add this line to your if(chances==totchan) call:
guess = number;

Otherwise if you keep guessing the wrong number the game will continue playing until you get the number correct. This way if you still miss it, the game will end correctly and allow you to either exit or try again.

After removing the bad parts and fixing the cout structures I was able to compile and run your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.