Cannot use cout / endl if extern "C"

Hope someone can help me with this little problem as I am not getting at all. First, heres the code:

#include<string> #include<iostream> #include<Windows.h> using namespace std; extern "C" { #include<hidsdi.h> #include<SetupAPI.h> } int main() { int iQuit; cout << "Testing Program" << endl; return 0; } 

This will not allow me to use the std file (i.e. cout, cin, endl, etc.). This will allow me to use it when I take out all the external C codes ... Why? And is there a way around this?

EDIT: Sorry, forget to tell you the exact error: it says the identifier "cout" is undefined

thanks

+6
source share
2 answers

I found a problem, I did not add directories in the correct order in VC ++ directories.

The order should be:

 C:\WinDDK\7600.16385.1\inc\ddk $(VCInstallDir)include $(VCInstallDir)atlmfc\include C:\WinDDK\7600.16385.1\inc\api $(WindowsSdkDir)include $(FrameworkSDKDir)\include 

I don’t know why it should be in this order, but now it works ... Very strange ...

+1
source

There is something wrong with your compilation environment. There is nothing wrong with this code. It compiles and works fine.

In a comment on the question you are saying:

I am learning to write a driver to do things with my devices, such as keyboards and mice, so I use WDK. Correct me if I am wrong, but I thought you need to use extern "C" to use these header files?

In fact, you just need to write code in C, not C ++ for driver development.

+3
source

Source: https://habr.com/ru/post/914978/


All Articles