本文介绍了未声明函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用stoi将字符串转换为整数,但它说它没有声明。我有标准库和包括,但它仍然说[错误]'stoi'没有在这个范围内声明
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 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.
推荐答案
。确保您的编译器设置正确和/或您的编译器支持C ++ 11。
std::stoi
was introduced in C++11. Make sure your compiler settings are correct and/or your compiler supports C++11.
这篇关于未声明函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!