0

This program compiles just fine:

#include <iostream>

#include <stdio.h>

#include <boost/program_options.hpp>

int main(int argc, char* argv[]) {
    std::cout << "Hello world" << std::endl;
}

This program gives a long compilation error:

#include <iostream>

namespace cio {
#include <stdio.h>
}

#include <boost/program_options.hpp>

int main(int argc, char* argv[]) {
    std::cout << "Hello world" << std::endl;
}

The full dump of the compilation error: http://codepad.org/aIcQqkgH

The linux command I'm using to compile the program is: c++ -o main.cpp.o -c main.cpp

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Paul Dejean
  • 3,458
  • 1
  • 9
  • 15
  • @hosch250 Why? namespace cio { #include } works just fine, exactly as one might expect. The program doesn't fail to compile until after you add the line: #include – Paul Dejean Nov 16 '14 at 06:24
  • 1
    related: http://stackoverflow.com/questions/12324302/is-it-ok-to-put-a-standard-pure-c-header-include-directive-inside-a-namespace (and many others). In short: Don't do it. – Rapptz Nov 16 '14 at 06:31

1 Answers1

0

Simply use

#include <cstdio>

http://en.cppreference.com/w/cpp/header/cstdio

This header is officially required to declare all the legacy C library declarations inside namespace std.

However, if you have a "problem" that requires these "solutions", indeed just namespace your own stuff. If it's actually Boost that pollutes the global namespace, then file a bug.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Is there a version of that for ncurses? #include ? – Paul Dejean Nov 16 '14 at 12:36
  • `ncurses` is not a standard header, the include in a namespace will probably work. the standard explicitly forbids doing anything before including a standard header that changes its meaning. – sp2danny Nov 16 '14 at 15:59