我不知所措 - 我刚刚接触 C++,但出于某种原因,这对我来说并不适用。所以我正在使用 Netbeans,并且我有以下主文件:
#include <cstdlib>
#include "functions.h"
using namespace std;
int main(int argc, char** argv) {
f("help");
return 0;
}
Functions.h 文件:
#include <string>
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
void f( string a );
#endif
和 Functions.cpp 文件:
#include "functions.h"
void f( string a ) {
return;
}
所以,长话短说,它无法编译。它说它无法理解字符串变量?我不明白,我尝试在整个地方移动字符串的包含,但似乎没有任何帮助。我该怎么办?
最佳答案
如果您尝试使用 std::string
, 你必须 #include <string>
在你的函数头中,并将其命名为 std::string
, 因为它在 std
中命名空间。
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <string>
void f( std::string a );
#endif
参见 this related post还有why is 'using namespace std' considered bad practice in C++?
关于c++ - 使用函数编译帮助文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14719035/