I would like to get an istream_iterator-style iterator that returns each line of the file as a string rather than each word. Is this possible?
Here is a solution. The exemple print the input file with @@ at the end of each line.
#include
#include
#include
#include
using namespace std;
class line : public string {};
std::istream &operator>>(std::istream &is, line &l)
{
std::getline(is, l);
return is;
}
int main()
{
std::ifstream inputFile("input.txt");
istream_iterator begin(inputFile);
istream_iterator end;
for(istream_iterator it = begin; it != end; ++it)
{
cout << *it << "@@\n";
}
getchar();
}
Edit : Manuel has been faster.