From: Michael Stevens (mail_at_[hidden])
Date: 2005-03-29 06:14:22
> 2)I am having problems with ublas vectors. I can't seem to load ublas
> vectors with data from a file. This is the method I use with std vectors:
> vector<float> v;
> ifstream infile("/home/will/roughwork/numbers.dat");
> istream_iterator<float> fin(infile),end;
> What is the best way load file data into a ublas vector?
I would use
infile >> v;
This works fine for data stored as text using 'infile << v'.
'operator >> ' does all the hard work of formating and making sure the number
of elements are correct.
Is there a reason for not using 'operator >>' or are you trying to do some
sophisticated serilaisation of uBLAS containers?
Incidentally I am not sure where the syntax
comes from. It not part of uBLAS!
> I can not get this to work with a ublas vector. Nor can I use copy, or
> assign from a std vector into a ublas vector.
Without detailed testing the following compiles fine with Boost_1_32_0
std::copy (sv.begin (), sv.end (), uv.begin ());
std::copy (uv.begin (), uv.end (), sv.begin ());