未在范围内声明Stoi-Code :: blocks [英] Stoi was not declared in scope - Code::blocks

查看:102
本文介绍了未在范围内声明Stoi-Code :: blocks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我试图通过在编译器标志中单击使g ++遵循C ++ 11 ISO C ++语言标准来告诉它与C ++ 11一起使用。

I'm trying to tell it to work with C++11 by clicking "Have g++ follow the C++11 ISO C++ language standard" in the compiler flags.

我在范围内未声明stoi,并且在 Code :: Blocks; 我在设置->编译器->编译器标志中添加了兼容性,但是它仍然不断给我该错误。

I'm getting stoi was not declared in scope, and I've added c++11 to Code::Blocks; I've added compatibility in Settings -> Compilers -> Compiler flags, but it still keeps giving me that error.

当我尝试执行atoi或strtol时,出现以下错误:

And when I try to do atoi or strtol I get the following error:


C:\Users\user\Desktop\Programming\NewProject\main.cpp | 19 |错误:
无法将'std :: string {aka std :: basic_string}'转换为'const char *'
将参数'1'转换为'long int strtol(const char *,char * *,int)'|

C:\Users\user\Desktop\Programming\NewProject\main.cpp|19|error: cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)'|

我的代码:

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

int main()
{

    string numberGuessed;
    int numberGuessedint = 0;

    do {

        cout << "Guess a number between 1 and 10: ";
        getline(cin, numberGuessed);
        numberGuessedint = stoi(numberGuessed);
        cout << numberGuessedint << endl;


    } while(numberGuessedint != 4);

    cout << "You win!" << endl;

    return 0;

}


推荐答案

是MinGW中与Code :: Blocks捆绑在一起的已知错误。

It is a known bug in MinGW bundled with Code::Blocks.

您可以应用补丁: http://tehsausage.com/mingw-to-string

或下载最新版的MinGW(最好带有线程支持,因为您也缺少它)并替换您现在拥有的一个。

Or download fresh version of MinGW (preferable with threading support, as you lack it too) and replace one you have right now.

这篇关于未在范围内声明Stoi-Code :: blocks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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