📄 pex2_7.cpp
字号:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main(void)
{
char cryptstr[] = "ngzqtcobmuhelkpdawxfyivrsj";
ifstream fin;
ofstream fout;
char infilename[28];
char line[80];
int i;
cout << "Enter the file name: ";
cin >> infilename;
fin.open(infilename, ios::in | ios::nocreate);
if (!fin)
{
cerr << "Cannot open file " << infilename << endl;
exit(1);
}
fout.open("crypfile", ios::out | ios::trunc);
// read lines from fin until end of file
while(fin.getline(line,80,'\n'))
{
i = 0;
// look at each character of the NULL-terminated string
while (line[i])
{
// translate each alphabetic character
if (isalpha(line[i]))
// convert to lower case and translate
line[i] = cryptstr[tolower(line[i]) - 'a'];
i++;
}
fout << line << endl;
}
}
/*
<Run>
Enter the file name: txt2_7_8.dat
<file "crypfile">
fbmx mx n qnfn cmet fbnf
ftxfx fbt xpeyfmpk fp dwpownllmko
trtwzmxtx 2.7 nkq 2.8.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -