为什么这个简单的C++程序不能编译?
Why won't this simple C++ program compile?
这是我非常简单的C++函数:
#include <string.h>
void myFunc(void * param)
{
string command;
}
为什么它不编译?
% CC -c -o testFunc.o testFunc.C
"testFunc.C", line 6: Error: string is not defined.
1 Error(s) detected.
<string.h>
来自C,定义了C字符串处理函数,如memcmp
和strcpy
,而不是C++类string
。在标准C++中,它的头是<string>
,类string
在名称空间std
中。
它并不是因为它告诉你的原因而编译的:
Error: string is not defined.
将<string.h>
更改为<string>
。
还要确保您使用的是正确的命名空间。您可以通过以下方式完成:
using std::string;
或
std::string command;
更多解释:
<string.h>
用于C中的C字符串- CCD_ 11用于C++中的C字符串
- CCD_ 12用于C++CCD_
相关文章:
- 为什么我的程序不能显示斐波那契级数?
- 为什么一个简单的程序不能立即启动
- 为什么这个信号处理程序不能捕获 SIGHUP 或 SIGQUIT?
- 为什么使用 exec() 重新启动程序不能正常工作?
- 为什么一个简单的"Hello World"风格的程序不能用Turbo C++编译?
- 为什么这个程序不能运行,但它会构建
- 为什么C++应用程序不能创建像php,html和css这样的接口?
- 为什么我的程序不能输出 i?
- 为什么他的语法正确的程序不能在带有llvm编译器的Xcode IDE上编译?
- 为什么我的程序不能识别素数
- 为什么我的hello world程序不能在c ++中工作?
- 为什么这个简单的C++程序不能编译?
- 这个使用标准库的非常简单的C++程序不能使用 GCC 编译
- 为什么程序不能立即输出?
- 为什么这个程序不能输出正确的异常?
- 图形程序不能在borlandc++中运行.我能做什么呢?
- 程序不能读取文件
- C程序不能处理与c++相关的错误
- Visual Studio Express 2012中的c++程序不能使用.csv,但可以使用.txt
- 为什么我的多线程程序不能正确终止