How can i use getline function to display pointer to an array.

how can i use cin.getline function to display an array whose size is not determined and it is dynamically allocated in the memory. little helpline will be highly appreciated.
Like this
1
2
3
4
5
    vector<string> lines;
    string line;
    while ( getline(cin,line) ) {
        lines.push_back(line);
    }

1
2
3
4
5
6
std::vector<std::string> lines;

for (std::string line; std::getline(std::cin, line); lines.push_back(line));

for (const auto& line : lines)
    std::cout << line << '\n'

Topic archived. No new replies allowed.