File I/O in C++
I'm doing some things with File I/O in C++ right now. My question is, is there a way to read in a line into a variable of type double instead of a string?
For example, say the text file that I am reading in appears like this:
12.32
223.21
123.64
Is there any way to read the entire line into a variable of type double instead of a string so that I can compare them?
Bare bones:
#include <ifstream> double f, g, h; std::ifstream file( filename ); file >> f >> g >> h;
#include <iostream>int main(){ using namespace std; ifstream fin(<filename>); double a, b, c; fin >> a >> b >> c; // etc... return 0;}
Quote:Original post by Mxz
Slight correction to both posts, the correct header is <fstream>.
[smile]
why not use #include <ifstream> if its only for input?
Quote:Original post by philipptrQuote:Original post by Mxz
Slight correction to both posts, the correct header is <fstream>.
[smile]
why not use #include <ifstream> if its only for input?
Because the header <ifstream> does not exist.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement