VC++创建多级目录源代码

本文介绍了如何使用VC++创建多级目录,提供了两个关键函数:IsPathExist()用于判断目录是否存在,CreateDirectoryEx()用于创建目录。代码示例包括递归创建目录的逻辑,确保路径中每一级目录都得以创建。源代码已上传至百度网盘,可下载参考。
摘要由CSDN通过智能技术生成

  VC++开发常用功能一系列文章 (欢迎订阅,持续更新...)

第5章:VC++创建多级目录源代码

源代码demo已上传到百度网盘:永久生效  ,代码实现了一次创建多级目录 功能如:D:\test\abc\xyz

主要是用来两个封装函数

1. // 判断目录(不能用来查询根目录,否则总是失败.)是否存在的函数
 static BOOL IsPathExist(char* lpszPath)
 {
     USES_CONVERSION;
     //char* szTemp = W2A(lpszPath);
     char szTemp[MAX_PATH]={0};

以下是用VC++编写的多级反馈队列代码: ``` #include<iostream> using namespace std; const int MAX = 100; // 队列最大长度 const int LEVEL = 3; // 多级反馈队列的级数 struct PCB { int id; // 进程ID int arrivalTime; // 到达时间 int needTime; // 运行所需时间 int priority; // 优先级 int level; // 所在级数 int runTime; // 已运行时间 }; class Queue { private: PCB queue[MAX]; // 队列数组 int front, rear; // 队头和队尾指针 public: Queue() { front = rear = 0; } // 构造函数 bool isEmpty() { return front == rear; } // 判断队列是否为空 void enQueue(PCB p); // 入队 PCB deQueue(); // 出队 PCB getFront(); // 获取队头元素 }; void Queue::enQueue(PCB p) { if ((rear + 1) % MAX == front) { // 队列已满 cout << "The queue is full!" << endl; return; } queue[rear] = p; rear = (rear + 1) % MAX; } PCB Queue::deQueue() { if (isEmpty()) { // 队列为空 cout << "The queue is empty!" << endl; PCB p; p.id = -1; return p; } PCB p = queue[front]; front = (front + 1) % MAX; return p; } PCB Queue::getFront() { if (isEmpty()) { // 队列为空 cout << "The queue is empty!" << endl; PCB p; p.id = -1; return p; } return queue[front]; } int main() { Queue q[LEVEL]; // LEVEL级队列数组 int timeSlice[LEVEL] = { 4, 8, 16 }; // 每级队列的时间片 int currentTime = 0; // 当前时间 // 输入进程信息 int n; cout << "Please input the number of processes: "; cin >> n; PCB p[MAX]; cout << "Please input the information of each process(ID, arrival time, need time, priority): " << endl; for (int i = 0; i < n; i++) { cin >> p[i].id >> p[i].arrivalTime >> p[i].needTime >> p[i].priority; p[i].runTime = 0; p[i].level = 0; } // 处理进程 int finished = 0; // 已完成进程数 while (finished < n) { // 还有进程未处理完 // 将到达时间在当前时间之前的进程加入第0级队列中 for (int i = 0; i < n; i++) { if (p[i].arrivalTime <= currentTime && p[i].runTime == 0) { q[0].enQueue(p[i]); } } // 处理第0级队列中的进程 int i = 0; while (!q[i].isEmpty()) { PCB current = q[i].getFront(); q[i].deQueue(); // 运行时间小于时间片,进程运行结束 if (current.needTime - current.runTime <= timeSlice[i]) { currentTime += current.needTime - current.runTime; current.runTime = current.needTime; cout << "Process " << current.id << " finished at time " << currentTime << endl; finished++; } // 运行时间大于时间片,进程移动到下一级队列末尾 else { currentTime += timeSlice[i]; current.runTime += timeSlice[i]; current.level = (i + 1) % LEVEL; q[current.level].enQueue(current); } } // 队列为空,当前时间自增1 if (q[i].isEmpty()) { currentTime++; } } return 0; } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

keivin2006

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值