-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExer17_38.cpp
More file actions
28 lines (28 loc) · 828 Bytes
/
Exer17_38.cpp
File metadata and controls
28 lines (28 loc) · 828 Bytes
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
// Warning: this is for verification. It cannot work properly.
// This program uses data file ./data/paragraph.
#include <cstddef>
#include <cstring>
#include <iostream>
#include <fstream>
using std::size_t;
using std::cout;
using std::endl;
using std::ifstream;
int main(int argc, char* argv[])
{
if(argc != 2)
return -1;
ifstream is(argv[1]);
char sink[80] = {'\0'};
size_t size = 80;
char delim = ' ';
while(is.getline(sink, size, delim)) {
size_t cnt = is.gcount();
cout.write(sink, cnt);
memset(sink, '\0', size);
}
return 0;
}
// Note: once is.getline reads (size - 1) characters, it seems that the state of
// the stream is not good. Empty line is not read. But we reset sink every time
// after finish using it, so the empty line could be output normally.