如何限制文件大小,以便我的程序在变大之后创建一个新文件?并编辑新创建的文件的名称
How do I limit the file size so my program creates a new file after it becomes too large? and edit the name of the newly created file?
当我运行代码时,它构建了文本文件,该文件很快超过了我可以有效地使用它的大小。
我将如何设置文本大小的尺寸限制,以便创建一个新的文本文件,并使用上一个文件的标题 1?
#include <iostream>
#include <vector>
#include <string.h>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
void Crack(string password, vector<char> Chars)
{
ofstream myfile;
myfile.open ("pass.txt");
myfile<<"PASSWORDs TO CRACK: 0 to "<<password<<endl;
int n = Chars.size();
int i = 0;
while(true)
{
i++;
int N = 1;
for(int j=0;j<i;j++)N*=n;
for(int j=0;j<N;j++)
{
int K = 1;
string crack = "";
for(int k=0;k<i;k++)
{
crack += Chars[j/K%n];
K *= n;
}
myfile<< crack<<" "<<endl;
if(password.compare(crack) == 0){
myfile<<"Cracked password: "<<crack<<endl;
return;
myfile.close();
}
}
}
}
int main()
{
vector<char> Chars;
for(char c = '0';c<='z';c++){
if(islower(c) || isdigit(c))Chars.push_back(c);
}
Crack("zzzzzzzzzzzzzzzzzz", Chars);
}
您可以使用ostream::tellp
为您提供当前文件大小。如果超过限制,请关闭流并创建一个新文件。
" title 1"是什么意思?您是指文件名还是要在每个文件中打印一个标头?
相关文章:
- 终端不会为C++文件创建.exe文件吗
- 如何从具有两列的.txt文件创建并行数组?
- 从 .lib 文件创建一个.dll文件
- 如何从输入文件 c++ 创建随机名称生成器
- 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- 如何为多个目录中的多个文件创建生成文件?
- 在编译时从 c++ 文件创建枚举
- 如何在运行时从 c++ 中的 DLL 文件创建对象?
- 文件创建并不总是成功
- 如何使用 QFile、c++ 从文件创建整数数组
- 您可以使用 makefile 从 .o 对象文件创建 C++ 文件吗?
- 从函数中的dat文件创建一个2维数组
- 如何为 cpp 和 h 文件创建别名(并忽略编译器__attributes__)
- 如何从现有的生成文件创建 CMake 文件?
- 为什么我无法使用文本文件创建文件映射?
- 通过读取文件创建映射<字符串,矢量>时如何管理内存<string>
- 从文本文件创建 2D 字符串矢量
- ofStream: - 尽管文件创建了,但文本文件上没有输出
- 从语言文件创建JSON对象
- 将文本文件创建到节点.js的插件C++