函数 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.
相关文章