简体   繁体   English

在c ++中,Netbeans IDE抛出“无法解析标识符字符串”

[英]In c++, Netbeans IDE throws “Unable to resolve identifier String”

I am getting a couple of errors that I am confused about 我遇到了一些我很困惑的错误

There is this function declaration that Netbeans IDE keeps throwing an error about 有此函数声明,Netbeans IDE不断抛出有关以下内容的错误:

    string  GetValue(const std::string& key);

The error I am getting is- 我得到的错误是-

Unable to resolve identifier String 无法解析标识符字符串

What am I doing wrong here? 我在这里做错了什么?

I assume you've remembered to include the header: 我假设您记得包括标头:

#include <string>

Then you can then use as indicated above 然后您可以按照上面的指示使用

std::string GetValue(const std::string& key);

or 要么

using namespace std;
string GetValue(const string& key);

#include <...> #include <...> #include <...> #include <...>

using namespace std; 使用名称空间std;

... ...

string GetValue(const string& key); 字符串GetValue(const string&key);

... ...

That's all 就这样

The other answers are correct, but I would not recommend polluting your namespace by using using namespace std; 其他答案是正确的,但我不建议using namespace std;来污染您的命名using namespace std; instead, just rename all of the calls that use a string with std::string . 相反,只需使用std::string重命名所有使用string的调用。

This is much more concise and helps with auto-completion. 这更加简洁,有助于自动完成。

Try this 尝试这个

std::string GetValue(const std::string& key);

Best if you added the namespace in the header file so you don't have to qualify the std namespace everywhere in your code. 最好将名称空间添加到头文件中,这样就不必在代码中的所有位置限定std名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM