-
Notifications
You must be signed in to change notification settings - Fork 148
/
file_test.cpp
30 lines (26 loc) · 962 Bytes
/
file_test.cpp
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
29
30
#include <iostream>
#include <native/native.h>
using namespace native;
// usage: (executable) src_file dest_file
int main(int argc, char** argv) {
if(argc < 3) {
std::cout << "usage: " << argv[0] << " SRC_FILE DEST_FILE" << std::endl;
return 1;
}
// read contents from source and then write it to destination.
file::read(argv[1], [=](const std::string& str, error e){
if(e) {
std::cout << "file::read() failed: " << e.str() << std::endl;
} else {
std::cout << str.length() << " bytes read from: " << argv[1] << std::endl;
file::write(argv[2], str, [=](int nwritten, error e){
if(e) {
std::cout << "file::write() failed: " << e.str() << std::endl;
} else {
std::cout << nwritten << " bytes written to: " << argv[2] << std::endl;
}
});
}
});
return run();
}