G
Gustav Lead
Hi all,
I have trouble reading back floating point data from a file.
It appears as if the tokens for positive and negative infinity (1.#INF
and -1.#INF) that my implementation writes get misinterpreted (to 1.0
and -1.0) when I try to read them back in.
#include <fstream>
#include <limits>
void somefunction()
{
double d_infinity = std::numeric_limits<double>::infinity();
std:fstream output;
output.open("file.txt");
output << d_infinity;
output.close();
double d_test1 = 0;
std::ifstream input;
input.open("file.txt");
input >> d_test1;
input.close();
}
The contents of "file.txt" is "1.#INF".
At the end of the function the value of d_test1 is 1.0 .
Trying to read in more data after that will fail, because the "#INF"
fragment remains in the stream.
Is this a problem of my STL implementation (I am using MSVC 7.1), or do
I have to make some change to my code to get this to work correctly?
Thanks in advance,
G L
I have trouble reading back floating point data from a file.
It appears as if the tokens for positive and negative infinity (1.#INF
and -1.#INF) that my implementation writes get misinterpreted (to 1.0
and -1.0) when I try to read them back in.
#include <fstream>
#include <limits>
void somefunction()
{
double d_infinity = std::numeric_limits<double>::infinity();
std:fstream output;
output.open("file.txt");
output << d_infinity;
output.close();
double d_test1 = 0;
std::ifstream input;
input.open("file.txt");
input >> d_test1;
input.close();
}
The contents of "file.txt" is "1.#INF".
At the end of the function the value of d_test1 is 1.0 .
Trying to read in more data after that will fail, because the "#INF"
fragment remains in the stream.
Is this a problem of my STL implementation (I am using MSVC 7.1), or do
I have to make some change to my code to get this to work correctly?
Thanks in advance,
G L