Function stoi not declared(函数 stoi 未声明)
问题描述
我正在尝试使用 stoi
将字符串转换为整数,但是它说它没有被声明.我有标准库和 <string>
包括在内,但它仍然说 [Error] 'stoi' is not declared in this scope
I'm trying to use stoi
to convert a string to an integer, however it says it's not declared. I have the standard library and the <string>
included, but it still says [Error] 'stoi' was not declared in this scope
代码如下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
string end, init;
cout << "Introduction" << endl;
cout << "Start time (xx:yy)" << endl;
cin >> init;
string hours0 = init.substr(0,2);
int hours = stoi(hours0);
cout << hours << endl;
system("pause");
return 0;
}
请告诉我为什么它不起作用,或者给我第二个选择.
Either tell me why it isn't working, or give me a second option to do it, please.
推荐答案
std::stoi
是在 C++11 中引入的.确保您的编译器设置正确和/或您的编译器支持 C++11.
std::stoi
was introduced in C++11. Make sure your compiler settings are correct and/or your compiler supports C++11.
这篇关于函数 stoi 未声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:函数 stoi 未声明
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01