问题是很简单啦,虽然看起来简单,想起来简单,但是但是整整用起来的时候发现根本无法实现。无论是用C++的fstream中的文件流,还是用C的stdlib的FILE都不行,exe文件可以打开,可以复制,但是复制之后的文件还有复制之前的文件内容根本不一样,现在贴上来的是主要的代码,用的是ifstream的,FILE我也试过了,同样没有用,而且,复制出来的结果比不上这个完整
void MainProcessor::read()
{
std::cout << " Please Insert File Name(*.*) " << std::endl;
std::cin >> file_name;
std::ifstream in;
in.open(file_name, std::ios::binary | std::ios::in | std::ios::app, _SH_DENYNO);
in.read((char*)a, 100000000);
int b = in.gcount();
if (length_of_file > b)
{
length_of_file = b;
}
if (b == 0)
{
std::cout << "No such file or the file is empty,try again" << std::endl;
is_read_file = false;
}
else
{
std::cout << "Read Success!" << std::endl;
is_read_file = true;
std::cout << std::endl;
std::cout << "There are " << b << "chars in the file" << std::endl;
std::cout << std::endl;
}
in.close();
}
这里是读入文件
void MainProcessor::write()
{
std::cout << "Your new locked_file_name?(*.*)" << std::endl;
std::cin >> lock_it_file_name;
std::ofstream out(lock_it_file_name);
if (out.is_open())
{
out.write((char*)a, (length_of_file)*sizeof(char));
out.close();
} std::ifstream in;
in.open(lock_it_file_name, std::ios::binary | std::ios::in | std::ios::app, _SH_DENYNO);
in.read((char*)compare, 100000000);
int b = in.gcount();
}
上面是写入的文件
在附件上由我复制之前(B1-B.txt,是exe文件,为了防止风险,特意改成txt文件,更改后缀名之后便可以打开),后面的是复制之后的文件(asd.txt,同上)
文件无法添加到附件,还请各位劳心到百度盘去下载一下
我是调试了好长时间无论如何调试不出来了- -,求大神帮助啊!