输出string vector到file

#include <fstream>
#include <iterator>
#include <string>
#include <vector>

int main()
{
    std::vector<std::string> example;
    example.push_back("this");
    example.push_back("is");
    example.push_back("a");
    example.push_back("test");

    std::ofstream output_file("./example.txt");
    std::ostream_iterator<std::string> output_iterator(output_file, "\n");
    std::copy(example.begin(), example.end(), output_iterator);
}
http://stackoverflow.com/questions/6406356/writing-vector-values-to-a-file
posted on 2015-07-29 12:02  minggoddess  阅读(433)  评论(0编辑  收藏  举报