gpt4 book ai didi

c++ - 未声明字符串?

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:23 24 4
gpt4 key购买 nike

#include <string.h>
using namespace std;
namespace charcount
{
int ShowPerCent();
int PerCent();
int Values(char letter);
int analize(string var);
}

这段代码是我项目的“functions.h”的一部分。这说:

functions.h: 7:13: error: 'string' was not declared in this scope

我不明白为什么这么说。我尝试使用 std::string 并没有。有人知道会发生什么吗?如果您需要更多信息,请询问。

最佳答案

正确的 header 是<string> .将包含指令更改为:

#include <string>

C++ 标准库头文件.h 结尾.

using namespace std; 被认为是非常糟糕的做法,尤其是在头文件中。这会用 std 中的名称污染全局命名空间命名空间并将所述污染传播到包含它的任何文件。

关于c++ - 未声明字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15883214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com