Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.76 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Read floating point numbers into a dynamically allocated while increasing the size of the array while reading the file
  2. ifstream input("my-file.txt");
  3. vector<float> myValues;
  4.  
  5. for (float f; input >> f; )
  6.     myValues.push_back(f);
  7.        
  8. ifstream input("my-file.txt");
  9. vector<float> myValues;
  10.  
  11. myValues.insert(myValues.begin(),
  12.                 istream_iterator<float>(input),
  13.                 istream_iterator<float>());
  14.        
  15. ifstream input("my-file.txt");
  16. vector< vector<float> > myValues;
  17.  
  18. for (string line; getline(input, line); ) {
  19.     stringstream lineStream(line);
  20.  
  21.     vector<float> thisLine;
  22.  
  23.     thisLine.insert(thisLine.begin(),
  24.                     istream_iterator<float>(lineStream),
  25.                     istream_iterator<float>());
  26.     myValues.push_back(thisLine);
  27. }