gpt4 book ai didi

c++ - stoi 没有在此范围内声明?

转载 作者:行者123 更新时间:2023-11-27 23:02:14 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用 stoi()string 转换为 int 但我收到的错误是 error: 'stoi ' 未在此范围内声明。这是给定的代码。

#include <iostream>
#include <string>

int main()
{
std::string str1 = "45";
std::string str2 = "3.14159";
std::string str3 = "31337 with words";
std::string str4 = "words and 2";

int myint1 = std::stoi(str1);
int myint2 = std::stoi(str2);
int myint3 = std::stoi(str3);
// error: 'std::invalid_argument'
// int myint4 = std::stoi(str4);

std::cout << "std::stoi(\"" << str1 << "\") is " << myint1 << '\n';
std::cout << "std::stoi(\"" << str2 << "\") is " << myint2 << '\n';
std::cout << "std::stoi(\"" << str3 << "\") is " << myint3 << '\n';
//std::cout << "std::stoi(\"" << str4 << "\") is " << myint4 << '\n';
}

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