Reading a line from a file

I have a text file "weblog.txt". I need to display each line individually and store the lines in a vector of strings. I know how to open the file, but I was wondering if anyone knows how to access and cout the lines of the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <utility>

int main()
{
    std::vector<std::string> lines;

    {
        std::ifstream in ("file.txt");
        std::string line;
        while(std::getline(in, line))
        {
            lines.push_back(std::move(line));
        }
    }

    for(std::string &line : lines)
    {
        std::cout << line << std::endl;
    }
}
Last edited on
Topic archived. No new replies allowed.