Last active
April 15, 2019 22:32
-
-
Save samwightt/22bd2f6ef5d830eb467197a9a2d7562a to your computer and use it in GitHub Desktop.
Creates a random test file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Generates a random text file using only characters from the keyboard. | |
Change the i variable for shorter or longer lengths. */ | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include <ctime> | |
using namespace std; | |
int main(void) { | |
srand(time(NULL)); | |
int length; | |
string filename; | |
cout << "Enter a file length." << endl; | |
cin >> length; | |
cout << "Enter a file name." << endl; | |
cin >> filename; | |
string allowedChars = "1234567890-=`qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?\n"; | |
fstream fout(filename, fstream::out); | |
if (!fout) { | |
cout << "There was an error creating the file."; | |
return 0; | |
} | |
for (int i = 0; i < length; i++) fout << allowedChars[rand() % allowedChars.length()]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated because it was breaking for some things.