
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.76 KB | hits: 13 | expires: Never
Read floating point numbers into a dynamically allocated while increasing the size of the array while reading the file
ifstream input("my-file.txt");
vector<float> myValues;
for (float f; input >> f; )
myValues.push_back(f);
ifstream input("my-file.txt");
vector<float> myValues;
myValues.insert(myValues.begin(),
istream_iterator<float>(input),
istream_iterator<float>());
ifstream input("my-file.txt");
vector< vector<float> > myValues;
for (string line; getline(input, line); ) {
stringstream lineStream(line);
vector<float> thisLine;
thisLine.insert(thisLine.begin(),
istream_iterator<float>(lineStream),
istream_iterator<float>());
myValues.push_back(thisLine);
}