0

I have a variable with type std::deque<float>, I'm sriting its contents to a file like following:

std::deque<float> queue;
// ...
std::ofstream file ("out.txt");
if (file.is_open())
{
    file.precision(12);
    std::copy(queue.begin(), queue.end(), std::ostream_iterator<float>(file, ";"));
}
file.close();

Is there a straightforward way to read it back from file like the way I wrote it? I mean without reading file and then looping?

guneykayim
  • 5,210
  • 2
  • 29
  • 61
  • See the reading in part of the selected answer to the duplicate. It applies to `std::deque` too. – juanchopanza May 29 '14 at 07:55
  • @juanchopanza That pesky `;` makes it a little more non-conforming that the straight-up linked answer (nice answer, btw), which assumes whitespace separation to allow those istream iterators to function. Hopefully the OP figures that out. – WhozCraig May 29 '14 at 07:57
  • @WhozCraig Good point. guneykayim, if the duplicate is not useful let me know and I can re-open this question. – juanchopanza May 29 '14 at 08:00
  • Well, I don't have to separate with `;`. It is working for me. – guneykayim May 29 '14 at 08:27

0 Answers0