i have a problem with reading from a file, and converting content to double. I have read the solutions from stackoverflow but nothing works.
i have this input file:
1291.23
291.493
558.089
309.266
513.656
491.44
429.234
851.345
589.192
535.873
802.469
713.604
1002.42
997.973
513.656
313.709
407.018
624.738
460.337
526.986
473.667
1202.36
and the program:
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sstream>
using namespace std;
void main() {
char* filename = "mr1.txt";
ifstream fin;
fin.open(filename);
float d;// = 0.0;
int v = 0;
while (v < 21){
fin>>d;
if(v >= 2 || v < 15){
cout<<d<<endl;
}
v++;
}
}
the output is: 1291 for 12 times
How can i convert from these file to double without problem? Thanks!
As a quick sanity check, try just copying the entire file to standard output, something like this: