Jump to content
  • Advertisement
Sign in to follow this  
Third

File I/O in C++

This topic is 4508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
#include <iostream>

int main()
{
using namespace std;
ifstream fin(<filename>);
double a, b, c;
fin >> a >> b >> c;

// etc...

return 0;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!