lundi 24 août 2015

How to read file as vector

I have data like this

4.0 0.8
4.1 0.7
4.4 1.1
3.9 1.2
4.0 1.0

I have written my program

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main() {
vector<double> v;
ifstream in("primer.dat");
double word;
while(in >> word)
v.push_back(word);
for(int i = 0; i < v.size(); i++)
cout << v[i] << endl;
}

But now I have realized that for further calculations in my code,I need data as (vector <vector> double).I would prefer not to reshape the vector.Is it possible to read data as vector of vectors?

Aucun commentaire:

Enregistrer un commentaire