blob: 7e12cf7df7e5882ca66dfc97d1022972c3f57311 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include <cstdio>
#include <string>
#include <unistd.h>
std::string getline() {
std::string result;
while (true) {
int r;
char c;
do
r = read(fileno(stdin), &c, 1);
while (r == -1 && errno == EINTR);
if (r <= 0 || c == '\n')
return result;
result += c;
}
}
void input_copy_loop() {
std::string str;
while (str = getline(), !str.empty())
printf("read: %s\n", str.c_str());
}
int main() {
input_copy_loop();
return 0;
}
|