Thread: Stdlib header help

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    75

    Exclamation Stdlib header help

    Can someone please tell me why I am getting this error. I included <stdlib> (Im using visual 2005 pro so .h is not needed), but im not sure what happened.

    c:\documents and settings\hp_administrator\my documents\visual studio 2005\projects\fire\fire\mainfire.cpp(2) : fatal error C1083: Cannot open include file: 'stdlib': No such file or directory

    P.s. I did attempt to add .h at the end and got 11 errors

    And as ALWAYS thanks

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by wikipedia.org
    stdlib.h is the header of the general purpose standard library of C programming language which includes functions involving memory allocation, process control, conversions and others. It is compatible with C++ and is known as cstdlib in C++. The name "stdlib" stands for standard library.
    source = wiki

    Quote Originally Posted by MacGaIn
    (Im using visual 2005 pro so .h is not needed)
    having a different compiler/ide doesnt change the fact of having to include a .h file (for C) or not.

    look up the C++ standard library to find out what header files you need. most common one would probably be iostream.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by MaGaIn View Post
    Can someone please tell me why I am getting this error. I included <stdlib> (Im using visual 2005 pro so .h is not needed), but im not sure what happened.

    c:\documents and settings\hp_administrator\my documents\visual studio 2005\projects\fire\fire\mainfire.cpp(2) : fatal error C1083: Cannot open include file: 'stdlib': No such file or directory

    P.s. I did attempt to add .h at the end and got 11 errors

    And as ALWAYS thanks
    The proper way to include that librairy is to include <cstdlib>.

    The 11 errors you get after including it are probably not related, but did not surface before because you were not getting that far in compiling your programs before (the compiler bailed out before it found them).
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    75

    Question

    Now I have the following errors:

    ------ Build started: Project: SafteyOffice, Configuration: Debug Win32 ------
    Compiling...
    mainfire.cpp
    c:\mainfire.cpp(5) : error C2146: syntax error : missing ';' before identifier 'name'
    c:\mainfire.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\mainfire.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\mainfire.cpp(6) : error C2146: syntax error : missing ';' before identifier 'password'
    c:\mainfire.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\mainfire.cpp(6) : error C2086: 'int string' : redefinition
    c:\mainfire.cpp(5) : see declaration of 'string'
    c:\mainfire.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\mainfire.cpp(19) : error C2446: '==' : no conversion from 'const char *' to 'int'
    There is no context in which this conversion is possible
    c:\mainfire.cpp(19) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [16]'
    c:\mainfire.cpp(19) : error C2446: '==' : no conversion from 'const char *' to 'int'
    There is no context in which this conversion is possible
    c:\mainfire.cpp(19) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [16]'
    Build log was saved at "file://c:\Documents and Settings\Mom\My Documents\Visual Studio 2008\Projects\SafteyOffice\SafteyOffice\Debug\Buil dLog.htm"
    SafteyOffice - 11 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Thanks as always

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That's great, but that gives us basically zero information. Why don't you start with posting line 5 of mainfire.cpp?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Jul 2007
    Posts
    75
    Here is a little bit:

    insert
    Code:
    #include<iostream>
    #include<string>
    #include<cstdlib>
    #include<windows.h>
    string name;
    string password;
    int selection;
    int report();
    int fire();
    using namespace std;
    
    int main()
    { 
    	cout << "Welcome to the Madigan Software Group Emergency Service" << endl;
    	cout << endl;
    	cout << "Please enter your login information" << endl;
    	cout << "User Name: "; cin >> name;
    	cout << "Password: "; cin >> password;
    	if (name=="madigansoftware" && password=="madigansoftware")
    	{
    		report();
    		return 0;
    	}

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    If you're using string from the std namespace, don't you think your using statement should come first?
    Code:
    #include<iostream>
    #include<string>
    #include<cstdlib>
    #include<windows.h>
    string name;
    string password;
    int selection;
    int report();
    int fire();
    using namespace std;
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Better yet, shift those global variables into say, main(), such that they become local variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jul 2007
    Posts
    75

    Smile

    It is now working. Thank You very much for you assistance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM