【发布时间】:2016-04-28 07:35:42
【问题描述】:
我有一个 c 和 cpp 文件
mycpp.cpp
fun()
{
//code goes here....
}
mycpp.h
#include<string>
struct str{
std::string a;
};
func();
myc.c
#include "mycpp.h"
func();
//with other c codes..
这是大型代码列表的一部分。所以它是通过 c++ 和 c 编译的。 我的问题是当 mycpp.h 通过 myc.c (包含在 myc.c 中)编译时,编译器抛出一个错误说 fatal error: string: No such file or directory
是否有一些包装机制来克服这种情况?
【问题讨论】:
-
检查this,它可能会有所帮助。
-
您在 C 中包含 C++ 结构,您期望什么?它们是不同的语言,当然不行。
-
您不能混合使用 2 种语言。您可以使用标准 c++ 编译器(例如 g++)编译 C,但反之则不行。
-
如果您能向我们展示一下为什么首先包含 mycpp.h 将会很有帮助。