外部"C"如何显示?允许在C文件中使用C ++代码? [英] how does extern "C" allow C++ code in a C file?

查看:180
本文介绍了外部"C"如何显示?允许在C文件中使用C ++代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在C文件中使用C ++代码,我读到我们可以做extern "C" { (where the c++ code goes here)},但是当我尝试使用cout打印出某些内容时,由于它无法识别库,我一直遇到错误.我想我对extern"C"如何允许您在C中使用C ++代码感到困惑.

In order to use C++ code in a C file, I read that we can just do extern "C" { (where the c++ code goes here)}, but when I try printing something out using cout, I keep getting an error because it does not recognize the library . I think I am just confused on how extern "C" allows you to use C++ code in C.

推荐答案

反之亦然.您可以使用extern C使用C ++编译器添加要编译为C代码的代码.

The opposite is true. You can use extern C to add code you want to compile as C code using a C++ compiler.

除非我缺少您无法使用C编译器编译C ++代码的东西.

Unless I'm missing something you can't compile C++ code with a C compiler.

这篇关于外部"C"如何显示?允许在C文件中使用C ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆