将std :: string转换为整数 [英] Convert std::string to integer
本文介绍了将std :: string转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将 std :: vector
中存储的 std :: string
转换为整数并将其作为参数传递给函数。
I'm trying to convert a std::string
stored in a std::vector
to an integer and pass it to a function as a parameter.
这是我的代码的简化版本:
This is a simplified version of my code:
vector <string> record;
functiontest(atoi(record[i].c_str));
我的错误如下:
error: argument of type ‘const char* (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::)()const’ does not match ‘const char*’
我如何做?
推荐答案
使用C ++ 11:
int value = std::stoi(record[i]);
这篇关于将std :: string转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文