C ++“std :: string未被声明为”错误 [英] C++ "std::string has not been declared" error

查看:1926
本文介绍了C ++“std :: string未被声明为”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在网站上的答案,但找不到任何答案帮助我。

I've been looking for an answer on websites but couldn't find any answer that helped me.

我有一个代码,像建议)添加这些行:

I have a code that uses strings when i tried (like suggested) to add these lines:

using namespace std;
using std::string;
#include <string>

我试图单独使用每一个,我试过所有的一起。最好的情况是当所有的字符串错误消失,但我有另一个奇怪的错误,在行使用std :: string,错误是:std :: string尚未声明。
任何想法?

I tried to use each of them seperately and I tried all of them together. The best situation was when all of the string errors disappeared but I had another weird error on the line "using std::string" and the error was: std::string has not been declared. Any ideas? Thanks guys.

推荐答案

先放入 #include< string>

在标题中避免使用语句,因为您可能会将各种内容导入许多编译单元。 使用std :: string 在标题中可能是可以接受的,但是 using namespace std 强>,因为它将在所有编译单元中造成如此多的命名空间污染。 std命名空间不断扩展(看看C ++中的所有新东西),所以你不想在升级编译器时修复大量的错误。

Avoid using statements in headers as you potentially bring in all sorts of stuff into many compilation units. using std::string is perhaps acceptable in a header but using namespace std certainly isn't as it will cause so much namespace pollution in all compilation units. The std namespace is continuously expanding (look at all the new stuff in C++), so you don't want to have to fix lots of errors when upgrading your compiler.

这篇关于C ++“std :: string未被声明为”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆