File Split 1.0

本文介绍了一个使用C++实现的文件分割工具,通过指定源文件、起始偏移量和结束偏移量,可以将文件分割成指定大小的片段。文章详细展示了如何读取文件、处理偏移量并创建目标文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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

Stack (most recent call first): File "F:\QYY3.5\sd-webui-forge-aki-v1.0\python\Lib\site-packages\torch\storage.py", line 469 in __getitem__ File "F:\QYY3.5\sd-webui-forge-aki-v1.0\python\Lib\site-packages\safetensors\torch.py", line 310 in load_file File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules_forge\patch_basic.py", line 38 in loader File "F:\QYY3.5\sd-webui-forge-aki-v1.0\backend\utils.py", line 26 in load_torch_file File "F:\QYY3.5\sd-webui-forge-aki-v1.0\backend\loader.py", line 238 in split_state_dict File "F:\QYY3.5\sd-webui-forge-aki-v1.0\backend\loader.py", line 274 in forge_loader File "F:\QYY3.5\sd-webui-forge-aki-v1.0\python\Lib\site-packages\torch\utils\_contextlib.py", line 116 in decorate_context File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules\sd_models.py", line 504 in forge_model_reload File "F:\QYY3.5\sd-webui-forge-aki-v1.0\python\Lib\site-packages\torch\utils\_contextlib.py", line 116 in decorate_context File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules\processing.py", line 804 in manage_model_and_prompt_cache File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules\processing.py", line 836 in process_images File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules\txt2img.py", line 131 in txt2img_function File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules_forge\main_thread.py", line 30 in work File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules_forge\main_thread.py", line 48 in loop File "F:\QYY3.5\sd-webui-forge-aki-v1.0\modules\launch_utils.py", line 557 in start File "F:\QYY3.5\sd-webui-forge-aki-v1.0\launch.py", line 50 in main File "F:\QYY3.5\sd-webui-forge-aki-v1.0\launch.py", line 54 in <module>
03-22
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、付费专栏及课程。

余额充值