Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:43:07+00:00 2026-06-03T07:43:07+00:00

Take a look at this tiny program. #include <iostream> int main(){ int var =

  • 0

Take a look at this tiny program.

#include <iostream>

int main(){

  int var = atoi("-99");      //convert string to int
  var = abs(var);             //takes absolute value
  std::cout << var+1 <<'\n';  //outputs 100

  return EXIT_SUCCESS;
}

Compiling creates the following errors messages:

$ g++ -o main main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:13: error: ‘atoi’ was not declared in this scope
main.cpp:6:16: error: ‘abs’ was not declared in this scope
main.cpp:9:10: error: ‘EXIT_SUCCESS’ was not declared in this scope

Understandable. All of these exist in the “cstdlib” header which I neglected to include.
However, compiling with:

$ g++ -std=c++0x -o main main.cpp 

creates no issues.


looking at the source of the “cstdlib” header, I see the following code at the bottom:

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#  if defined(_GLIBCXX_INCLUDE_AS_TR1)
#    error C++0x header cannot be included from TR1 header
#  endif
#  if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
#    include <tr1_impl/cstdlib>
#  else
#    define _GLIBCXX_INCLUDE_AS_CXX0X
#    define _GLIBCXX_BEGIN_NAMESPACE_TR1
#    define _GLIBCXX_END_NAMESPACE_TR1
#    define _GLIBCXX_TR1
#    include <tr1_impl/cstdlib>
#    undef _GLIBCXX_TR1
#    undef _GLIBCXX_END_NAMESPACE_TR1
#    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
#    undef _GLIBCXX_INCLUDE_AS_CXX0X
#  endif
#endif

I’m not sure if that is relevant or not.. full header file code here

my ultimate question is, does the new standard guarantee that all of cstdlib will be brought in at a global namespace when you include iostream?

I can’t find any documentation on the matter. Appears that way to me, does it appear that way to you?

gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:43:08+00:00Added an answer on June 3, 2026 at 7:43 am

    my ultimate question is, does the new standard guarantee that all of cstdlib will be brought in at a global namespace when you include iostream?

    No. You should #include it yourself if you need its functionality. If you get it “for free” with <iostream>, that’s a sign that your <iostream> header requires it, but then you’re relying on an implementation detail of your C++ library.

    Btw., #include <cstdlib> is not guaranteed to bring C functions into the global namespace (although it commonly does so in C++ implementations); it is guaranteed to put them in the namespace std:

    Except as noted in Clauses 18 through 30 and Annex D, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3).

    (Standard, section 17.6.1.2)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this code: public class Test { public static void main(String...
Take a look at this basic class: namespace AcmeWeb { public string FirstName {
Take a look at this site . I am trying to make the main
Take a look at this snippet below: <script> $(function(){ var to_username = alex; window.Persona
Take a look at this code: #include <cassert> #ifdef DEBUG #define ASSERT(expr) assert(expr) #else
Take a look at this snippet: var obj = { fn: function () {return
Lets take a look to this two functions: std::string get_string() { std::string ret_value; //
take look at this: http://www.templatemonster.com/demo/35403.html In this template you can click on the image
take a look at this example code: public class Comment { private Comment() {
Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.