0

我的问题很简单,但我似乎无法找到它。我想知道使用stoi. 我正在使用atoi,它适用于

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

但是当我使用stoi. 谢谢

4

1 回答 1

1

您需要#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

于 2015-10-21T13:30:29.547 回答