Code Blocks+程序多开

本文介绍了如何在CodeBlocks中配置环境以实现客户端与服务器端的多实例运行。通过设置Environment选项,取消特定勾选,避免冲突,从而成功启动多个CodeBlocks实例进行Socket编程的调试和测试。

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

在Socket编程中,遇到客户端与服务器端的通信问题,需要运行多个实例,用的是Code Blocks。
尝试Code Blocks多开。
先上运行成功截图。
编辑页面
命令行窗口
1,点击Settings,选中Environment,结果如下;
取消勾选
2,取消对应两项的勾选,下一次生效;
3,重启Code Blocks,点击Settings->Environment,看步骤2是否生效(即是否取消了勾选);
4,如果生效,则多开几次Code Blocks(此前勾选了那两项,是不能的),可以得到开头的多开效果。

题目描述 Description 本题中,需要实现一个包含空间回收的文件读写类 Where the north wind meets the sea There's a river full of memory Sleep, my darling, safe and sound For in this river all is found —— All is Found 文件存储操作是编程的重要部分,其分为 ASCII 文件存储和二进制文件存储。文件其实是一块白纸,交由你创作出块状、链状、树状的画作,以及本题中需要实现的 MemoryRiver 类。 MemoryRiver 类是为了方便对文件的操作而封装了一些操作。该类的功能有 与一个文件名(string)绑定 往文件中写入一个 int 或 T类型对象 往文件中读取一个 int 或 T类型对象(T 的大小大于 int) 删除并回收一块空间。 请实现一个类模板 MemoryRiver.hpp,来实现文件的读写。 该类模板的声明为 template<class T, int info_len = 2> class MemoryRiver; 其中,T 是需要存储的原子对象的类,info_len 是存储文件头部预留出来的 int 的个数(1_base)。 MemoryRiver 的存储策略为在文件首预留出 info_len 个 int 作为存储一些参数的空间,这些 int 在 initialise() 函数种被初始化为 0。 请完成 MemoryRiver.hpp 内的代码: MemoryRiver.hpp #ifndef BPT_MEMORYRIVER_HPP #define BPT_MEMORYRIVER_HPP #include <fstream> using std::string; using std::fstream; using std::ifstream; using std::ofstream; template<class T, int info_len = 2> class MemoryRiver { private: /* your code here */ fstream file; string file_name; int sizeofT = sizeof(T); public: MemoryRiver() = default; MemoryRiver(const string& file_name) : file_name(file_name) {} void initialise(string FN = "") { if (FN != "") file_name = FN; file.open(file_name, std::ios::out); int tmp = 0; for (int i = 0; i < info_len; ++i) file.write(reinterpret_cast<char *>(&tmp), sizeof(int)); file.close(); } //读出第n个int的值赋给tmp,1_base void get_info(int &tmp, int n) { if (n > info_len) return; /* your code here */ } //将tmp写入第n个int的位置,1_base void write_info(int tmp, int n) { if (n > info_len) return; /* your code here */ } //在文件合适位置写入类对象t,并返回写入的位置索引index //位置索引意味着当输入正确的位置索引index,在以下三个函数中都能顺利的找到目标对象进行操作 //位置索引index可以取为对象写入的起始位置 int write(T &t) { /* your code here */ } //用t的值更新位置索引index对应的对象,保证调用的index都是由write函数产生 void update(T &t, const int index) { /* your code here */ } //读出位置索引index对应的T对象的值并赋值给t,保证调用的index都是由write函数产生 void read(T &t, const int index) { /* your code here */ } //删除位置索引index对应的对象(不涉及空间回收时,可忽略此函数),保证调用的index都是由write函数产生 void Delete(int index) { /* your code here */ } }; #endif //BPT_MEMORYRIVER_HPP tips: 二进制文件的读写 (可参考 https://en.cppreference.com/w/cpp/io/basic_fstream 等资料) //T类型的对象t的二进制文件读写 file.write(reinterpret_cast<char *>(&t), sizeof(T)); file.read(reinterpret_cast<char *>(&t), sizeof(T)); //将指针移动到[文件头指针+offset]处 file.seekp(offset); 可以使用文件(多)链表的思想来实现空间回收。 也可以用类似内存池的思想,多一个文件进行管理。 可以隐式的增加文件头部的 info_len 的长度供自己使用,但是需要在 get_info 和 write_info 时作一个转换的映射避免冲突 本题未对原子化操作做出要求,但在大作业中推荐在每个函数调用前打文件,调用后关闭文件。 评测的文件数量限制为 20,但最好不要超过 2 个文件 2≤infolen2≤infolen 解决这道题目
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值