I am pretty new to programming in C++, I want to display
How to display produce a output.txt file in this format.
A B C D E F G H I J K L M N O P Q R S T U V W X
Y ZT W G X Z R L L N H A I A F L E W G Q H V R N V D U
in text file but i am not sure why they display as rubbish.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
void random (std::ostream& output)
{
int letter[26];
int i,j,temp;
srand(time(NULL));
for(i=0; i<26; i++)
{
letter[i] = i+1;
output<<(char)(letter[i]+'A'-1)<<" ";
//by ending endl here i am able to display but the letter will display in horizontal which is not what i wanted
}
for(i=0; i<26; i++)
{
j=(rand()%25)+1;
temp = letter[i];
letter[i] = letter[j];
letter[j] = temp;
output<<((char) (letter[i]+'A'-1))<<" ";
}
}
For the future – don’t use std::endl because it also flush stream buffer, which might be unwanted. Use ‘\n’ instead. But whole function can be much simpler: