c++ - 使用函数编译帮助文件

标签 c++ compilation

我不知所措 - 我刚刚接触 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/

相关文章:

C++ 打印 DBL_MAX

c++ - 在 C++ 中将节点附加到树(引用和指针帮助。)

c++ - 有没有办法将我的 GCL Lisp 文件与 Windows 上的单独 C++ 程序链接?

c++ - 链接究竟是如何工作的?

java - 弃用的编译错误

c++ - ethtool 获取永久 MAC 地址返回全 0

c++ - Boost lock free queue asserts 用于简单的赋值和析构函数

c++ - 如何在 C++11 中返回类成员 vector

c# - 加快 MSBuild 构建过程

c++ - 为什么 `abs()` 的实现方式不同?