use*_*678 6 c++ string parsing compiler-errors string-parsing
我正在测试std::stoi下面链接中找到的函数:http:
//en.cppreference.com/w/cpp/string/basic_string/stol
但是我得到了错误:
在名称空间std中没有名为stoi的成员.
我该怎么办?请指教谢谢.
PS:我正在使用Xcode Ide来做我的c ++.
#include <iostream>
#include <string>
int main() {
std::string test = "45";
int myint = std::stoi(test);
std::cout << myint << '\n';
}
Run Code Online (Sandbox Code Playgroud)
图片


Lih*_*ihO 10
std::stoi仅在C++ 11之后可用.如果您没有C++ 11支持,这里是基于以下内容的C++ 03解决方案std::istringstream:
std::string test = "45";
std::istringstream is(test);
int myInt;
if (is >> myInt)
std::cout << myint << std::endl;
Run Code Online (Sandbox Code Playgroud)
你只需要 #include <sstream>
首先,您需要一个支持C++ 11的编译器,并且需要以"C++ 11模式"(在某些情况下)进行编译.
其次,如果这实际上是一个intellisense问题(看起来可能是这样),那么它可能只是你的IDE还不支持C++ 11.
| 归档时间: |
|
| 查看次数: |
10211 次 |
| 最近记录: |