c++中用于stoi关键字的库

what library to use for stoi keyword in c++

本文关键字:关键字 stoi 用于 c++      更新时间:2023-10-16

我的问题很简单,但我似乎找不出来。我想知道使用stoi时包含什么库。我用的是atoi

效果很好
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

但是当我用stoi运行时,我得到"stoi未声明"。由于

您需要#include <string>并使用理解c++ 11的编译器。最小的例子:

#include <string>
#include <cassert>
int main()
{
  std::string example = "1234";
  int i = std::stoi(example);
  assert(i == 1234);
  return 0;
}

例如,用g++ -std=c++11编译