File I/O in C++

Started by
4 comments, last by Mxz 18 years, 3 months ago
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?
Advertisement
Bare bones:

     #include <ifstream>    double f, g, h;    std::ifstream file( filename );    file >> f >> g >> h; 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
#include <iostream>int main(){  using namespace std;  ifstream fin(<filename>);  double a, b, c;  fin >> a >> b >> c;  // etc...  return 0;}
Slight correction to both posts, the correct header is <fstream>.

[smile]
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 philipptr
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?



Because the header <ifstream> does not exist.

This topic is closed to new replies.

Advertisement