I am using Codeblocks 17.12 and have already set compiler settings to C++11 standard. I am studying from Bjarne Stroustrup's book "Programming - Principles and Practice using C++". In his book he asked to include "std_lib_facilities.h". I copied it from his website and saved in "include" folder of "Mingw" folder. After that I proceeded to make a simple program:
#include<iostream>
#include "std_lib_facilities.h"
main()
{
std::cout<<"Hello world";
}
But the compiler is showing following errors and warnings:
warning: This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp] error: template-id 'do_get<>' for 'String > std::__cxx11::messages<char>::do_get(std::messages_base::catalog, int, int, const String&) const' does not match any template declaration note: saw 1 'template<>', need 2 for specializing a member function template
Also the error which is showing is in the 1971 line of the header file "locale_facets_nonio.h"
.
I tried to find out the solution to this problem in other forums, but could not find a satisfactory answer.
Some are saying we should not use this file "std_lib_facilities.h"
at all as it is using deprecated or antiquated headers.
we should not use this file "std_lib_facilities.h" at all as it is using deprecated or antiquated headers.
You should #include
standard headers as you use them. The std_lib_facilities.h
might get out of sync.
#include<iostream>
#include "std_lib_facilities.h"
int main() {
std::cout<<"Hello world";
}
should rather be
#include<iostream>
// #include "std_lib_facilities.h" Remove this entirely!
int main() {
std::cout<<"Hello world";
}
Using more standard features like std::string
should be:
#include<iostream>
#include<string>
int main() {
std::string hello = "Hello world";
std::cout<<hello;
}
Extending further, reading the #include std_lib_facilities.h
in your books example should probably become to expand the actually necessary standard header includes for your compilable and productive code.
Here's just a default starting template as used by Coliru
#include <iostream>
#include <vector>
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec)
{
for (auto& el : vec)
{
os << el << ' ';
}
return os;
}
int main()
{
std::vector<std::string> vec = {
"Hello", "from", "GCC", __VERSION__, "!"
};
std::cout << vec << std::endl;
}
Sure you could gather up the
#include <iostream>
#include <vector>
in a separate header file, but that would be tedious to keep in sync of what you need in particular with all of your translation units.
Another related Q&A: