[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppFileToVector
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppFileToVector
(C++) How can I read a file in a std::vector?
std::vector<std::string> fileToVector(const std::string& fileName) { assert(fileExists(fileName)==true); std::vector<std::string> myVector; std::ifstream in (fileName.c_str()); std::string myString; for (int i=0; !in.eof(); ++i) { in >> myString; myVector.push_back(myString); } return myVector; }
- include <vector>
- include <fstream>
- include <string>
- include <cassert>
Other code snippets
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
