stoi and stoll in c++
stoi and stoll in c++
我在程序顶部的声明中有 #include(字符串),但是当我尝试运行stoi(string)或stoll(string)时,我收到以下错误。我正在运行Cygwin g ++ v4.5.3。
Z:\G\CSCE 437>g++ convert.cpp -o conv 转换.cpp:在此范围内未声明
void transfer(std::string*)': convert.cpp:103:36: error:
stoll' 的功能 转换.cpp:116:35:错误:"stoi"未在此范围内声明
fileTime[numRec] = stoll(result[0]); //converts string to Long Long
if(numRec = 0){
beginningTime = fileTime[0];
}
fileTime[numRec] = timeDiff;
hostName[numRec] = result[1];
diskNum[numRec] = stoi(result[2]);
type[numRec] = result[3];
offset[numRec] = stoi(result[4]);
fileSize[numRec] = stoi(result[5]);
responseTime[numRec] = stoi(result[6]);`
其中结果是一个字符串数组。
这些功能是 C++11 中的新功能,仅当您使用命令行选项 -std=c++11
指定该版本的语言(或在某些旧版本上-std=c++0x
时,GCC 才使其可用;我认为您在 4.5 版中需要它)。
如果由于某种原因无法使用 C++11,则可以使用字符串流进行转换:
#include <sstream>
template <typename T> from_string(std::string const & s) {
std::stringstream ss(s);
T result;
ss >> result; // TODO handle errors
return result;
}
或者,如果你感到受虐狂,C 在 <cstring>
中声明strtoll
中的 C 函数。
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp