您好,我正在编写一个非常基本的密码生成器,我想使用 ofstream 将循环的输出写入文件。我的想法是每次循环运行时都会从数组中输出一个人声abc
。我不知道如何让它工作和观察。有更好的方法。
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <fstream>
using namespace std;
int main(){
srand(time(0));
cout << "You'r PW is: \t" << endl;
char abc [] {'A', 'a', 'B' ,'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'x', 'Y', 'y', 'Z', 'z'};
for(int i = 0; i <15; i++){
int randomNum = rand() % 53;
cout << abc[randomNum];
ofstream fob;
fob.open("contr.txt");
fob << abc[randomNum];
}
}
顺便说一句,我得到了像 ',' 和 '->' 这样的字符,它们不在我的数组中。