函数 stoi 未声明

Function stoi not declared(函数 stoi 未声明)

本文介绍了函数 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 未声明

基础教程推荐