std :: stoi不被eclipse识别 [英] std::stoi not recognized by eclipse

查看:464
本文介绍了std :: stoi不被eclipse识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统上,运行Windows 7 x64,Eclipse Luna和g ++ 4.9.2(通过cygwin安装),似乎std :: stoi从来没有被g ++声明。
根据文档,stoi是字符串库的一部分,所以显然我有 #include< string>



此外,我知道stoi是在C ++ 11中引入的,并且我为我的编译器(g ++)设置了适当的标志,即使这看起来像是一个 IDE错误 ,而不是编译器错误。



但是,在构建项目时,我会收到以下错误消息之一:

 错误:'stoi'不是'std'的成员
错误:函数'stoi'无法解析

如何解决这个问题?如何让Eclipse识别stoi?

解决方案

这需要相当多的挖掘,但显然,代码声明stoi在< basic_string.h> 中,它看起来像这样:

  #if(defined(__ GXX_EXPERIMENTAL_CXX0X__)&&&&&define(_GLIBCXX_USE_C99)\ 
&&!defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
#include< ext / string_conversions.h>
namespace std _GLIBCXX_VISIBILITY(默认)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
// 21.4数值转换[string.conversions]。
inline int
stoi(con​​st string& __str,size_t * __idx = 0,int __base = 10)
{return __gnu_cxx :: __ stoa< long,int>(& std :: strtol ,stoi,__str.c_str(),
__idx,__base); }

所以,很容易看到,为了拥有 std: :stoi 可用,必须确保以下内容:




  • __ GXX_EXPERIMENTAL_CXX_0X __

  • <$
  • c $ c> _GLIBCXX_HAVE_BROKEN_VSWPRINTF 是 NOT 定义的。


,如果您已启用自动完成功能,请检查这些设置并进行设置。



检查:只需开始输入在代码中,在一个新行,并看看自动完成(通常CTRL +空间)是否建议他们。如果它 - 它们被定义。如果没有,请继续阅读。



定义也很简单!导航到:项目 - >属性 - > C / C ++常规 - >路径和符号 - >符号选项卡



GNU C ++ ,然后点击添加,然后输入所需的名称。



点击确定并关闭属性窗口,添加所需的定义后,通过导航到* Project - > C / C ++ Index - > 重建 重建索引器。 / p>

PS在你的时候,你也可以定义下面的符号:
__ cplusplus 与值 201103L



(这将帮助设置各种其他选项,例如std :: unordered_set)。


On my system, running Windows 7 x64, Eclipse Luna, and g++ 4.9.2 (installed via cygwin), it seems std::stoi was never declared by g++. According to the documentation, stoi is part of the string library, so obviously I have #include <string>.

In addition, I know that stoi was introduced in C++11, and I have set the appropriate flags for my compiler (g++), even though this seems like an IDE error, rather than a compiler error.

Still, I would get one of the following error messages when building my project:

error: 'stoi' is not a member of 'std'
error: Function 'stoi' could not be resolved

How do I fix this? How do I make Eclipse recognize stoi?

解决方案

This took quite a bit of digging, but apparently, the code declaring stoi is located inside <basic_string.h>, and it kind of looks like this:

#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \
 && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
#include <ext/string_conversions.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
  // 21.4 Numeric Conversions [string.conversions].
  inline int
  stoi(const string& __str, size_t* __idx = 0, int __base = 10)
  { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
                __idx, __base); }

So, it's quite easy to see that in order to have std::stoi available, one would have to make sure the following:

  • __GXX_EXPERIMENTAL_CXX_0X__ is defined.
  • _GLIBCXX_USE_C99 is defined.
  • _GLIBCXX_HAVE_BROKEN_VSWPRINTF is NOT defined.

Now, in Eclipse, if you have auto-completion turned on, checking for these and setting them up is quite easy!

Checking: Simply start typing them anywhere in the code, on a new line, and see if the auto-completion (usually CTRL+Space) suggests them. If it does - they're defined. If they're not, keep reading.

Defining is easy as well! Navigate to: Project -> Properties -> C/C++ General -> Paths and Symbols -> Symbols tab.

Click on GNU C++ from the options list to the left, and then click on Add, and simply give the name needed.

Click okay and close the properties window, after you've added the required definitions, and rebuild the indexer by navigating to *Project -> C/C++ Index -> Rebuild.

P.S. While you're at it, you may want to also define the following symbol: __cplusplus with value 201103L.

(This will help set various other options, such as std::unordered_set, for instance).

这篇关于std :: stoi不被eclipse识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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