Does there exist a function in the STL that will get the next float from a file?
e.g.:
Data.txt:
blah blah blah blah blah
blah blah blah blah blah
blah 0.94 blah blah blah
std::istream inputFile(Data.txt);
float myNumber = inputFile.GetNextFloat();
std::cout << myNumber << std::endl; // Prints "0.94"
The I/O stream functions in C++ (and likewise the stdio functions in C) are designed to read formatted input. That is, they are tailored to reading values of types expected by the program. There is nothing which tries to read values from a stream and only accept a specific type, discarding other values. Also, it is somewhat unclear what a "float" might be: for example, "+1" is a perfectly good "float" for some while others might want it to contain at least a decimal point, possibly even at least one digit after the decimal point.
C++2011 and Boost (if you don't have access to a C++2011 implementation) implement regular expressions and you should be able to detect the next floating point number matching your preferred definition using this. Here is a simple demo of this technique:
#include <iostream>
#include <string>
#include "boost/regex.hpp"
namespace re = boost;
int main()
{
re::regex floatre("^[^-+0-9]*([-+]?[0-9]+\\.[0-9]+)(.*)");
for (std::string line; std::getline(std::cin, line); )
{
re::smatch results;
while (re::regex_match(line, results, floatre))
{
std::cout << " float='" << results[1] << "'\n";
line = results[2];
}
}
}