How to write vector values to a file

前端 未结 4 769
闹比i
闹比i 2020-12-23 17:13

I have a large vector.

The ways that I use multiply the run-time of the program hugely. The first is write all values to a string as they are calculated using

4条回答
  •  醉酒成梦
    2020-12-23 17:47

    Assuming you have C++11:

    #include 
    #include 
    #include 
    
    int main()
    {
        std::vector v{ "one", "two", "three" };
        std::ofstream outFile("my_file.txt");
        // the important part
        for (const auto &e : v) outFile << e << "\n";
    }
    

提交回复
热议问题