ios::ate places the get-position pointer at the file end, enable tellg() to return the size of the f
2012-08-10 17:43
477 查看
#include <fstream> #include <iostream> #include <cstdlib> using namespace std; void print_error(const char* p1, const char* p2 = 0); int main(int argc, char* argv[]) { if (3 != argc) print_error("usage: function input_file output_file"); ifstream in(argv[1], ios::binary | ios::ate); if (!in) print_error("cannot open input file", argv[1]); long N = in.tellg(); char buffer ; in.seekg(ios::beg); ofstream out(argv[2], ios::binary); if (!out) print_error("cannot open output file", argv[2]); in.read(buffer, N); out.write(buffer, N); if (!in.good()) { print_error("something strange happened"); exit(1); } in.close(); out.close(); return 0; } void print_error(const char* p1, const char* p2) { if (p2) cerr << p1 << ' ' << p2 << endl; else cerr << p1 << endl; exit(1); }
相关文章推荐
- iOS每次启动都提示:Application windows are expected to have a root view controller at the end of application
- Linux - How to remove the new line at the end of file when using vim
- How to get the size of file in C++ - 在C++中如何获取文件的大小
- ios6.0之后单个屏幕旋转,不用根视图以及Application windows are expected to have a root view controller at the end of
- iOS 9出现错误Applications are expected to have a root view controller at the end of application launch
- Qt5:"Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document."错误
- 关于Application windows are expected to have a root view controller at the end of application launch
- C语言-何消除 warning no newline at the end of file
- mysql5.7.12/13在安装新实例时报错:InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero
- Application windows are expected to have a root view controller at the end of appliaction launch.
- Application windows are expected to have a root view controller at the end of application launch
- before we get to the end of our block
- warning: no newline at the end of file
- file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it 的解决
- by the end of, at the end of , in the end , to the end 的区别与用法
- 【Hackerrank】Get the value of the node at a specific position from the tail
- the diary of how to get a random word within a file
- pointer to ref of an array, and to the func that return a ref of an array
- Redirect the stream buffer of cout to a file with ios::rdbuf()
- Why do you need to put #!/bin/bash at the beginning of a script file?