I'm working with a project, but I can't find a way to store float numbers in a array. I have a .txt file (testfile.txt) with float numbers, like this
1.0 2.0
3.0 4.0
5.0 6.0
7.0 8.0
9.0 10.0
And I want to store it into a array. But when I do this, all my numbers are converted to integers. My program looks like this:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
double number[10];
ifstream infile;
infile.open("testfile.txt");
for(int a=0; a<10; a=a+1)
{
infile >> number[a]; // Reading from the file
cout << number[a] << endl;
}
}
And the output is like this
1
2
3
4
5
6
7
8
9
10
Can someone please explain to me what I'm doing wrong? I have tried a lot, thanks in advance!