blob: c1519e31aeb3ca18822c494129eb8dd53cc1a0ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include "stdin_to_file.hh"
#include <fstream>
#include <iostream>
long int stdin_to_file(const std::string& filename)
{
std::ofstream file_out;
std::string token;
// trying to open output file "data.out"
file_out.open(filename);
size_t res = 0;
// Read until eof or an error occurs
while (std::cin >> token)
{
res++;
file_out << token << '\n';
}
// stream is closed at the end of the scope
return res;
}
|