[英]Can't use cout/endl when extern “C”
I hope someone can help me on this small problem as I'm getting no where at all. 我希望有人能在这个小问题上为我提供帮助,因为我什么都没有。 Firstly, 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;
}
It won't let me use the std stuff (ie cout, cin, endl etc). 它不会让我使用std的东西(例如cout,cin,endl等)。 It will only allow me to use it when I take out all the extern "C" code... Why is that?
仅当我取出所有外部“ C”代码时,它才允许使用它……为什么? And is there a way around this?
有没有解决的办法?
EDIT: Sorry, forget to tell you the exact error: It says identifier "cout" is undefined 编辑:对不起,忘记告诉您确切的错误:它说标识符“ cout”未定义
Thanks 谢谢
There is something wrong with your compilation environment. 您的编译环境有问题。 There is nothing wrong with that code.
该代码没有错。 It compiles and runs fine.
它可以编译并运行良好。
In a comment to the question you say: 在对问题的评论中,您说:
I'm learning to write a driver so I can do stuff with my devices like keyboards and mouses, so I'm using the WDK.
我正在学习编写驱动程序,以便可以对键盘和鼠标等设备进行处理,因此我正在使用WDK。 Correct me if I'm wrong, but I thought you need to use extern "C" to use those header files?
如果我错了,请纠正我,但是我认为您需要使用extern“ C”来使用那些头文件?
In fact you should simply write code in C rather than C++ for driver development. 实际上,您应该只用C而不是C ++编写代码来进行驱动程序开发。
I've found out the problem, I weren't adding the directories in the correct order in VC++ Directories. 我发现了问题,我没有在VC ++目录中以正确的顺序添加目录。
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
Don't know why it needs to be in this order, but it works now... Very strange... 不知道为什么需要按此顺序运行,但是现在可以正常工作了……很奇怪……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.