+ 1

How to use vector instead of double array?

I wrote a cpp code, and I used " double stu[ ][ ]" And I filled that with .csv file with a function using ifstream fileobj(str,ios::in) Then I displayed it. But I don't know how to use vector instead and use ifstream again I would be thankful if someone help. This is my code : #include<iostream> #include<fstream> #include<iomanip> using namespace std; void getdata (char str[100],double stu[243][8]) ; int main() { double stu[243][8]; char str[100]="AP-Data.csv"; getdata(str,stu); for(int j=0;j<243;j++) { for(int i=0;i<8;i++) { cout<<stu[j][i]; cout<<"\t"; } cout<<"\n"; } return 0; } void getdata (char str[100],double stu[243][8]) { double m; char ch; int i,j; ifstream fileobj(str,ios::in); for(j=0;j<243;j++) { stu[j][0]=1; for(i=1;i<8;i++) { fileobj>>m; stu[j][i]=m; fileobj>>ch; } } fileobj.close(); for(j=0;j<243;j++)

27th Feb 2020, 5:47 PM
Abolfazl Fekri
Abolfazl Fekri - avatar
1 Réponse
+ 3
For using vector in cpp, firstly you have to include vector library which includes necessary functions like push_back() etc. You can do this by #include<vector> And you can define 2D vector by Vector<Vector<int>> temp; You can find other details on following link: http://www.cplusplus.com/forum/beginner/236646/
28th Feb 2020, 7:02 AM
Vijay Meena