Just for-loop 1:20 and append a (char) floor rand to the string by every iteration. If you want the - you should either do two for loops 5x4 or make a if(k%4==0) ofile<<"-"; continue; check. However, using continue is usually a bad programming habit.
For text files you just use some function nobody remembers. #include <fstream> and then some output file variable def.