12345678910111213141516171819202122232425262728
#include <iostream> #include <fstream> #include <vector> #include <string> int main(int argc, char **argv) { if (argc != 2) { std::cerr << "Usage: filereader FILE_TO_READ\n"; return 1; } std::ifstream ifs(argv[1]); if (!ifs) { std::cerr << "Can't open " << argv[1] << '\n'; return 1; } std::vector<std::string> v; std::string line; while (getline(ifs, line)) v.push_back(line); ifs.close(); for (auto& x: v) std::cout << x << '\n'; return 0; }
1234567891011
std::vector<std::vector<char>> v; std::string line; while (getline(ifs, line)) v.push_back(std::vector<char>(line.begin(), line.end())); ifs.close(); for (const auto& x: v) { for (const auto& y: x) std::cout << y; std::cout << '\n'; }