gpt4 book ai didi

c++ - 函数 stoi 未声明

转载 作者:IT老高 更新时间:2023-10-28 21:53:58 26 4
gpt4 key购买 nike

我正在尝试使用 stoi将字符串转换为整数,但它说它没有声明。我有标准库和 <string>包括在内,但它仍然显示 [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;

}

请告诉我为什么它不起作用,或者给我第二个选择。

最佳答案

std::stoi在 C++11 中引入。确保您的编译器设置正确和/或您的编译器支持 C++11。

关于c++ - 函数 stoi 未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22084783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com