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 未声明
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
