如何限制文件大小,以便我的程序在变大之后创建一个新文件?并编辑新创建的文件的名称

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?

本文关键字:文件 创建 一个 新文件 新创建 编辑 何限制 我的 程序 文件大小 之后      更新时间:2023-10-16

当我运行代码时,它构建了文本文件,该文件很快超过了我可以有效地使用它的大小。

我将如何设置文本大小的尺寸限制,以便创建一个新的文本文件,并使用上一个文件的标题 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"是什么意思?您是指文件名还是要在每个文件中打印一个标头?