Policy data structure on my compiler is not working - c++

I want to use a policy based data structure but my compiler keeps on giving me errors.
Here is what im using in my code:
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
Here are the error messages I recieve:
fatal error:
'ext/typelist.h' file not found
#include <ext/typelist.h>
and
error: function-like macro
'__GLIBC_PREREQ' is not defined
#if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
I've tried replacing the files over and over again but it keeps on telling me to continuously add new files that my computer does not have. I am using VS Code on a mac. Thank you.

The macro __GLIBC_PREREQ is defined in <cstdlib> , it is not to be guaranteed to be included by default. It looks like you had omitted some vital header or the implementations of those headers don't include <cstdlib>
PBDS requirec gcc, saying that you use VSCode IDE doesn't tell what compiler you're using.

Related

clangd language server gives weird errors. code compiles

I've got platformio project that compiles and works.
Using emacs + lsp-mode + clang.
One of the weird errors I get is for structures like this:
#include <queue>
#include <vector>
struct test_v{
std::vector<int> buff;
};
on the line #include <queue>
in included file: no type named 'pointer' in 'std::allocator_traits<std::allocator<int>>'
on the line of buff definition
In template: no member named 'value' in 'std::is_void<int>'
file is .hpp in case this matters
the config was incomplete and missing headers that define the needed std:: parts

After defining a function in another file, visual studio does not recognize the function

I'm creating windows console app that has many pages (split in files). I'm facing a problem when executing the program and Visual Studio throws 'startpage' identifier not found error (startpage is the function and the file name is startpage.h)
I've tried using:
external int startpage(); and
int startpage();.
I've tried changing only the function name too (so the file and function don't use the same name).
I have no idea why this is happening. Other files with different functions are working. The file "startpage.h" uses two functions defined in other files, and those are not throwing any errors.
#include "include/startpage.h"
#include <iostream>
#include <conio.h>
#include "include/concol.h"
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
startpage();
}
```
Here is the error:
Error code: C3861: 'startpage' identifier not found
Move #include "pch.h" to the top. The compiler ignores everything above the inclusion of precompiled header. – Igor Tandetnik
This worked!
Thank you so much guys!

IAR Workbench can't find std::string

I'm trying to compile CppUTest as a library on IAR Workbench v6.3.3 for the AVR UC3C0512C on Windows 7 x64 but when I compile it, it says that the std namespace is not defined.
Here is the snippet of code where I get the first error, the file is SimpleString.h:
#if CPPUTEST_USE_STD_CPP_LIB
#include <string>
#include <stdint.h>
SimpleString StringFrom(const std::string& other);
The last line contains the std::string and this brings me 190 errors all related to this. The message is:
Error[Pe276]: name followed by "::" must be a class or namespace name
C:\COM\SRC\cpputest35\include\CppUTest\SimpleString.h 143
I have tried using the line below but it does not help:
using namespace std;
Under Library Configuration I select Normal DLIB, I also tried with Full DLIB but IAR can't see the std library
Any ideas please?
According to the IAR manuals
The std namespace is not used in either standard EC++ or in Extended EC++. If you
have code that refers to symbols in the std namespace, simply define std as nothing;
for example:
#define std // Nothing here

C++ cout gives undeclared identifier

So, I have this question. Why does cout throws
error C2065: 'cout' : undeclared identifier
I am using Visual Studio 2012 as an IDE and I am writing a school project. I have everything done except an example file. So I am trying to write something on the screen like this:
#include "iostream"
#include "stdafx.h"
using namespace std;
int main()
{
cout<<"example";
return 0;
}
So the problem is with cout... printf works fine, but I want to use cout.
EDIT:
I've changed "" to <> but it is not helping. Also I am using this code only for example... This is not the whole project.
stdafx.h shall be the first include directive in your source file.
Switch files and convert the second include to <>, as other suggested.
#include "stdafx.h"
#include <iostream>
See this post for more information.
First of all:
#include <iostream>
instead of #include "iostream"
Secondly, it is generally considered bad practice to write using namespace std;, even though most courses start with that. It is better to only use what you actually need, in your case:
using std::cout;
#include "iostream"
should be
#include <iostream>
Quoting from this post:difference-between-iostream-and-iostream-quotes-in-include
By courtesy of #Jerry Coffin's answer:
When you use < >, the compiler only looks in the system-designated directory/directories (e.g., whatever you've set in the include environment variable) for the header.
When you use " ", the compiler looks in the local directory first, and if that fails, re-searches just like you'd used < >. Technically, (i.e., according to the standard) that doesn't have to be the "local" directory, but that's how it works in essentially every compiler of which I'm aware).
EDIT:
However, the root cause is that stdafx.h is a precompiled header. Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled. However, it is still better to use <> with iostream not to confuse reader of the code.
If you use #include <iostream> with the <> instead of "" then it should work. Right now, the compiler doesn't know where to find the iostream library.
Also, you might want to change cout<<"example"; to cout<<"example"<<endl; for a new line so that it formats correctly.
Came across this issue while trying to build a Dynamic Linked Library. Make sure that instead of the #include stdafx.h you specify the following include on the first line of your .cpp file:
#include "pch.h"
This should also be the case for VS2017 or earlier.
This error also occurred in the Visual Studio 2017 IDE. Moving stdafx.h to the top solved the error.
For more on stdafx.h, see What's the use for "stdafx.h" in Visual Studio?

How do I get a handle to split_winmain

I am trying to get a get the boost library program_options working on a simple windows console library.
I have linked in the library
C:\Program Files\boost\boost_1_40\lib\libboost_program_options-vc90-s-1_40.lib
Included the header files
#include <boost/program_options.hpp>
#include <boost/program_options/config.hpp>
#include <boost/program_options/option.hpp>
#include <boost/program_options/detail/cmdline.hpp>
#include <boost/program_options/detail/parsers.hpp >
Defined _WIN32 (But I don't think it is required.)
And I still keep getting the
Error 1 error C3861: 'split_winmain': identifier not found
It should be so simple but I can't get it to work. Can anyone tell me what I need to do here.
Joseph Shanahan
That function is declared in the boost::program_options namespace. If all you do is use its name alone, the compiler doesn't know what you're talking about. You have a few options:
Use the fully qualified name when you call it:
boost::program_options::split_winmain(...);
Tell the compiler which function you mean:
using boost::program_options::split_winmain;
split_winmain(...);
Bring the entire namespace into the current scope:
using namespace boost::program_options;
split_winmain(...);
Make a namespace alias:
namespace po = boost::program_options;
po::split_winmain(...);
I prefer the last one.
Do not define the _WIN32 macro; the compiler will do that for you when it's appropriate.