File Split 1.0

 main.cpp

 

 1 #include <iostream>
 2 #include <fstream>
 3 #include <stdlib.h>
 4 #include <string>
 5 #include <windows.h>
 6 
 7 using namespace std;
 8 
 9 int main ( int argc, char* argv[] ) {
10     if ( argc != 4 && argc != 5 ) {
11         cout << "File Split 1.0" << endl;
12         cout << "    Usage: fs <source file> <off begin> <off end> [<destination file>]" << endl;
13         cout << "    e.g. fs app.exe 0 127 0_127.dat" << endl;
14         cout << "    e.g. fs app.exe 0 127" << endl;
15         return -1;
16     }
17     fstream src ( argv[1], ios::in | ios::binary | ios::ate );
18     if ( src.is_open() ) {
19         long long srcSize = static_cast<long long> ( src.tellg() );
20         cout << "<source file> size: " << srcSize << " bytes" << "." << endl;
21         long lgBegin = strtol ( argv[2], NULL, 10 );
22         long lgEnd = strtol ( argv[3], NULL, 10 );
23         std::ios_base::seekdir offBegin = static_cast<std::ios_base::seekdir> ( lgBegin );
24         std::ios_base::seekdir offEnd = static_cast<std::ios_base::seekdir> ( lgEnd );
25         if ( offBegin >= 0 && offEnd < srcSize && offBegin <= offEnd ) {
26             string dstPath = "";
27             if ( argc == 5 ) {
28                 dstPath += argv[4];
29             } else {
30                 char buf[32];
31                 dstPath += ltoa ( lgBegin, buf, 10 );
32                 dstPath += "_";
33                 dstPath += ltoa ( lgEnd, buf, 10 );
34                 dstPath += ".bin";
35             }
36             cout << "Offsets with " << offBegin << " ~ " << offEnd << "." << endl;
37             fstream dst ( dstPath.c_str(), ios::out | ios::binary | ios::trunc );
38             if ( dst.is_open() ) {
39                 src.seekg ( offBegin );
40                 for ( int i = offBegin; i <= offEnd; i++ ) {
41                     dst.put ( src.get() );
42                 }
43                 dst.flush();
44                 dst.close();
45                 src.close();
46                 cout << "<destination file> expected size: " << offEnd - offBegin + 1 << " bytes" << "." << endl;
47                 fstream chk ( dstPath.c_str(), ios::in | ios::binary | ios::ate );
48                 if ( chk.is_open() ) {
49                     long long chkSize = static_cast<long long> ( chk.tellg() );
50                     chk.close();
51                     cout << "<destination file> actual size: " << chkSize << " bytes" << "." << endl;
52                     cout << "<destination file> state " << ( chkSize != offEnd - offBegin + 1 ? "bad" : "good" ) << "." << endl;
53                 } else {
54                     cout << "Can not open <destination file> file." << endl;
55                     return -1;
56                 }
57                 cout << "File split completed." << endl;
58                 return 0;
59             } else {
60                 src.close();
61                 cout << "Can not create <destination file> file." << endl;
62                 return -1;
63             }
64         } else {
65             src.close();
66             cout << "Invalid offsets. The allowed offsets is 0 ~ " << srcSize - 1 << "." << endl;
67             return -1;
68         }
69     } else {
70         cout << "Can not open <source file> file." << endl;
71         return -1;
72     }
73 }

附件1

转载于:https://www.cnblogs.com/rms365/p/11003282.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import tkinter as tk from tkinter import filedialog from common import LayoutCenter class EditForm: def __init__(self, master): self.master = master LayoutCenter(master, "修订评分标准") # 创建滚动条 vsb = tk.Scrollbar(master, orient=tk.VERTICAL) vsb.pack(side="right", fill="y") # 创建文本框并关联滚动条 self.text = tk.Text(self.master, yscrollcommand=vsb.set) self.text.pack(fill="y", expand=True) vsb.config(command=self.text.yview) self.create_menu() self.text.bind("<KeyRelease>", self.update_line_numbers) self.text.tag_configure("line_numbers", justify="right") # 添加行号标记 def update_line_numbers(self,event=None): self.text.delete("line_numbers") for i, line in enumerate(self.text.get("1.0", "end").split("\n")): self.text.insert(f"{i+1}.0", f"{i+1}\n", "line_numbers") def create_menu(self): menu = tk.Menu(self.master) self.master.config(menu=menu) file_menu = tk.Menu(menu) menu.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Open", command=self.open_file) file_menu.add_command(label="Save", command=self.save_file) file_menu.add_separator() file_menu.add_command(label="Exit", command=self.exit) def open_file(self): file_path = filedialog.askopenfilename() if file_path: with open(file_path, "r") as file: self.text.delete("1.0", "end") self.text.insert("1.0", file.read()) def save_file(self): file_path = filedialog.asksaveasfilename() if file_path: with open(file_path, "w") as file: file.write(self.text.get("1.0", "end")) def exit(self): self.master.destroy() def run(self): self.master.mainloop() root = tk.Tk() my_gui = EditForm(root) root.mainloop()
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值