hi guys, i'm just starting out c++.
Now the problem is, no matter whatever program i write, i'm getting this warning.

#warning This file includes at least one deprecated or antiquated header. \
Please consider using one of the 32 headers found in section of the \
C++ standard. Examples include substituting the <X> header for the <X.h> \
header for C++ includes, or <iostream> instead of the deprecated header \
<iostream.h>. To disable this warning use -Wno-deprecated.

one demo code:

#include <iostream.h>
int main()
{
    char *p = "hello world";
    cout<<p;
    return 0;
}

can anyone explain pls?
thanks
P.S: i use Code::Blocks

Dani AI

Generated

Short answer: the compiler is warning because you included an old, pre-standard header (<iostream.h>). Modern C++ uses the non-.h headers (for example <iostream>) and places the library names in the std namespace. As pointed out, that’s why switching to <iostream> produced “cout not declared” — you need to refer to std::cout (or bring the name into scope). ’s using namespace std; will hide the namespace issue, but there are better, safer options for real projects.

Corrected minimal example:

#include <iostream>
#include <string>

int main() {
    std::string s = "hello world";
    std::cout << s << std::endl;
    return 0;
}

Practical tips and gotchas:

  • Prefer std::string (or const char*) over assigning a string literal to char*; string literals are not meant to be modified.
  • Avoid using namespace std; in headers or large programs; either qualify names (std::cout) or use targeted using-declarations (using std::cout; using std::endl;) inside a narrow scope.
  • If you see other C headers (like <string.h>, <stdlib.h>), prefer their C++ counterparts (<cstring>, <cstdlib>); those put symbols in std.
  • In Code::Blocks make sure the file has a .cpp extension and is compiled as C++ (g++), and consider selecting a modern standard (e.g., -std=c++11) in the project build options.

If you maintain or compile legacy code that relies on old .h headers, you can keep it working on some compilers, but porting to the standard headers and std:: namespace is the right long-term fix.

Recommended Answers

All 5 Replies

Examples include substituting the <X> header for the <X.h> \
header for C++ includes, or <iostream> instead of the deprecated header \
<iostream.h>.

Um..... I think your compiler has said it all... Try actually reading it.

The way you've written your code is not per the current C++ standards. There are no headers that are part of the current standard that end with ".h"...

Um..... I think your compiler has said it all... Try actually reading it.

The way you've written your code is not per the current C++ standards. There are no headers that are part of the current standard that end with ".h"...

thanks for your reply.
Did you mean, i should use <iostream> instead of <iostream.h>?
well...i tried that. but then i'm getting errors like "cout was not declared in this scope" or "endl was not declared in this scope"..i think in this case they can't find the header files where these functions are written.
sorry for my bad english, i'm not native english speaker.
thanks to all.

>>Did you mean, i should use <iostream> instead of <iostream.h>?
That's exactly what I/it mean(s).

>>but then i'm getting errors like "cout was not declared in this scope" or "endl was not declared in this scope"..i think in this case they can't find the header files where these functions are written
Nope. It means you didn't resolve your namespace properly. All functions and objects that are members of the standard headers are declared within the "std" namespace. To get to them, you must resolve the namespace.

In other words, add the line using namespace std; after your header.

thanks to all.
I'm reading a crap book..!:icon_mad:
gotta change it.

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.