【发布时间】:2013-02-15 20:56:15
【问题描述】:
我之前遇到过这个问题,但找到了解决方法,只是这次没有解决方法。
我正在尝试使用 'stof' 函数,但我收到错误消息: “stof”不是“std”的成员 函数“stof”无法解析
如果显示在此页面上,我会以完全相同的方式使用它:http://www.cplusplus.com/reference/string/stof/
这是我的包括:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
那么,我做错了什么?如果找不到解决方案,是否有人可以指出另一种将字符串转换为浮点数并在字符串不兼容时抛出异常的方法?
编辑:使用示例程序和错误进行更新。
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string testString = "";
float testFloat = 0.0;
testFloat = std::stof(testString);
return 0;
}
我得到的错误是:
描述资源路径位置类型 'stof' 不是'std' main.cpp /Assignment/src 第 33 行 C/C++ 问题的成员
描述资源路径位置类型 函数 'stof' 无法解析 main.cpp /Assignment/src 第 33 行语义错误
【问题讨论】:
-
std::stof是 C++11 标准中的新内容。你确定你使用的是兼容 C++11 的编译器吗? -
我不确定,我对 C++ 不太熟悉,但我的命令之一是“-std=c++11”
-
你也可以试试 -stdlib=libc++
-
-stdlib=libc++ Nathan S 运气不好,谢谢
-
你不是偶然使用 MinGW 的吧?有一个 open bug report 可以解释为什么它不适合你。