Programming Language: C++
Write a program which reads a .csv file of double values (the .csvfile just contains 1 column of type double values) and stores theminto an array.
2345 123456 Show transcribed image text 2345 123456
Answer
If you have any doubts, please give mecomment…
#include<iostream>
#include<fstream>
using namespace std;
#define MAX_SIZE 50
int main(){
ifstream in;
in.open(“data.csv”);
if(in.fail()){
cout<<“Unable to open data.csv”<<endl;
return -1;
}
double values[MAX_SIZE];
int n=0;
while(!in.eof()){
in>>values[n];
n++;
}
cout<<“Successfully “<<n<<” values read fromfile”<<endl;
cout<<“The values are: “<<endl;
for(int i=0; i<n; i++){
cout<<values[i]<<” “;
}
cout<<endl;
return 0;
}
nagaraju@nagaraju-Vostro-3550:/Desktop/CHEGG/2019/April/18042019$ g++ readcsv.cpp nagaraju@nagaraju-Vostro-3550~/Desktop/CHEGG/2019/April/180420195 /a.out Successfully 4 values read from file The values are: 1.2 1.3 1.4 1.5