Skip to content

Instantly share code, notes, and snippets.

@nkoehring
Last active June 5, 2016 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkoehring/7d6a78d37652b1c432f2d9ce514ccc07 to your computer and use it in GitHub Desktop.
Save nkoehring/7d6a78d37652b1c432f2d9ce514ccc07 to your computer and use it in GitHub Desktop.
read line delimited floating numbers from a file
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main ()
{
double arr[5];
string tmp;
int i = 0;
ifstream fp("numbers.txt");
while (fp >> tmp)
arr[i++] = atof(tmp.c_str());
while(--i>=0)
cout << "Number " << i << " is " << arr[i] << endl;
return 0;
}
@nkoehring
Copy link
Author

Testfile

1.2
2.3
5.501
23.42
42.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment