通行证生成器:如何使每个密码使用新行

Pass Generator: How to make each password use a new line?

本文关键字:密码 新行 何使每 通行证      更新时间:2023-10-16

我编写了一个基本上生成密码的小型控制台应用程序。它询问用户他想要多少个密码以及每个密码应该有多少个字符。它将密码保存到文件中,旨在将每个密码放在不同的行上。目前,它要求用户输入字符长度/密码数量,但它将其全部放在一行上。

我该如何使每个密码都有自己的行?

string characters = "abcdefghi9182345$??=%(&)(%jklmnopqrstuv211935960473/=?$$=)&/$%=()wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!$%&/()=";
int length;
int pwds;
int usrInpt;
int num;
(

我知道我在上面的字符串中使用了一些字母/数字两次,但我这样做了,所以它更频繁地使用"$/(%(§"等字符(

        cin >> usrInpt;
        if (usrInpt == 1)
        {
            system("cls");
            cout << "You chose to generate a password!" << endl;
            cout << "How many passwords ?" << endl;
            cin >> pwds;
            cout << "How many characters ?" << endl;
            cin >> length;
            ofstream out_file;
            out_file.open("Passwords.txt");
            srand(time(0));
            for (int i = 0; i < pwds; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    num = rand() % 70 + 1;
                    out_file << characters[num];
                    system("cls");
                    cout << "Passwords.txt created!" << endl;
                }
            }

正如我所说,预期是每个密码都打印在自己的行上。

第二个循环之后和结束第一个循环之前添加一个out_file << std::endl;

for (int i = 0; i < pwds; i++)
    {
    for (int j = 0; j < length; j++)
        {
        }
    .... 
    out_file << std::endl;
    }

您还希望将"创建"消息移动到内部循环之外。