Stoi未在作用域中声明-代码::块
Stoi was not declared in scope - Code::blocks
编辑:我试图通过单击编译器标志中的"让g++遵循C++11 ISO C++语言标准"来告诉它使用C++11。
我发现stoi没有在scope中声明,并且我已经将c++11添加到Code::Blocks;
中。我已经在设置->编译器->编译器标志中添加了兼容性,但它仍然会给我带来错误。
当我尝试做atoi或strtol时,我会得到以下错误:
C: \Users\user\Desktop\Programing\NewProject\main.cpp|19|错误:无法将"std::string{aka std::basic_string}"转换为"const char*"对于参数"1"到"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;
}
这是与Code::Blocks捆绑在一起的MinGW中的一个已知错误。
您可以应用修补程序:http://tehsausage.com/mingw-to-string
或者下载新版本的MinGW(最好支持线程,因为你也缺乏它),并替换你现在拥有的一个。
要使用atoi
,您需要:
numberGuessedint = atoi(numberGuessed.c_str());
我正在编写一个对我有用的解决方案。正如我在大多数发布在堆栈溢出上的解决方案中发现的那样,早期版本的代码块包含一个错误。所以我删除了旧的代码块版本,并从代码块网站安装了新的17.12版本。
然后我只点击编译器标志中的"让g++遵循C++11 ISO C++语言标准"。
设置->编译器->编译器标志。
它对我有效(我使用的是windows7)。
相关文章:
- 我的代码中有错误,未声明的标识符
- 在多个头文件中从接口声明被覆盖的函数时,如何避免重复代码?
- 我如何在一个 if 语句中声明所有数字我尝试通过其他方式声明所有数字,如果一个接一个,但似乎代码有逻辑错误
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 在C++代码中使用的 C 标头中向前声明枚举
- C++代码中奇怪的未使用的静态字符串声明
- 如何将char数组声明为函数参数?或告诉我此代码中还有其他问题?
- 使用模板化代码前向声明类
- 这是有效的C++代码吗?(在声明范围之外使用本地类型)
- 如何使用声明类型简化此代码
- 模板函数声明为 void - 代码不起作用?
- 代码块编译错误.Cin 未在此范围内声明
- 模板化友元声明在 G++ 5.4.0 下不起作用 - 编译器错误或错误代码
- 无法使用在模板化基类 [C++] 中声明的枚举编译代码
- 以下代码运行后,如何在程序再次运行之前清除用户声明的变量 empName
- 声明原型时如何在主代码块中调用函数
- 声明全局变量 <vector>,代码将无法成功运行
- 有没有修复我的代码没有将 int 声明为我在 if else 循环中选择的内容
- 将代码声明放入字中(引用操作符和解引用操作符混淆)
- 如何为Arduino代码声明C++函数