#include <iostream>
#include <cstdlib>
#include <fstream>
//#include "list.cpp"
using namespace std;
int main()
{
list<string> list;
ifstream f("./src/main.cpp");
// Read the file into list
if (!f.is_open() || !GetLines(f, list).eof())
{
cout << "Error reading test2.cpp" << endl;
return EXIT_FAILURE;
}
// Print the contents
Print(list);
return 0;
}
istream& GetLines(istream& is, list<string>& list)
{
// 1. getline(is, list);
// 2.cin.getline(list, list.end(), '\n');
// 3. getline(cin, list, '\n');
return istream&;
}
I need to read lines from a file and write/append them into the list using std::getline
function, I've tried different approaches which give me
mostly this
error: no instance of overloaded function "getline" matches the argument list -- argument types are: (std::istream, std::__cxx11::list<std::string, std::allocator<std::string>>))
Getlines: Reads all lines from the stream into the specified list. The stored lines should not contain the newline characters. Returns the input stream object after reading all the lines.
param is: The input stream object param list: The list that contains all the lines in the input stream return std::istream& The input stream object after reading all the lines
file main.cpp
is main file of my project which has main body in it, which is written above the Getlines function. While Getline function is in another file called list.cpp
which is included through #include "list.cpp".