我很新的C++编程,我想显示随机化字符输出到文本文件
如何以这种格式显示产生output.txt文件。
在文本文件A B C d E F G H I J K L M N 2 O P Qř式T U V W X arrow-
T W&ģX Z R L L N H A我A F L E W^g^Q H V RÑV dù
,但我不知道为什么它们显示为垃圾。
#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))<<" ";
}
}
你的问题是什么? – jeschafe 2012-07-17 16:23:12
如何以此格式显示生成output.txt文件。 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 Z – newbieprogrammer 2012-07-17 16:26:23
所以你想写一个愚蠢的凯撒密码?耶稣,那很难理解。 – akappa 2012-07-17 16:35:00