writing content of vector to file c++
c++, file-io
Solution
You may use
std::copy(temp.rbegin(), temp.rend(),
std::ostream_iterator<int>(outputfile, "\n"));
And this code:
for(int i=temp.size()-1;i>=0;i--)
outputfile<<temp[i]<<"\n";
works fine on my windows with vs12.
Problem
I've tried to write my vector content into a file. To do that I've written a piece of code like: ``` int main() { ofstream outputfile("test.txt"); vector<int>temp; temp.push_back(1); temp.push_back(2); temp.push_back(3); for(int i=0;i<temp.size();i++) outputfile<<temp[i]<<"\n"; } ``` When I write this I can easly do what I wanted. the content of file is: 1 2 3 However, when I want to write my vector to file from reverse(like below).I get nothing.Just empty file.Is there anyone to help me ? Thanks in advance. ``` for(int i=temp.size()-1;i>=0;i--) outputfile<<temp[i]<<"\n"; ```