pex2_8.cpp
来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 46 行
CPP
46 行
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main(void)
{
char decryptstr[] = "ghfpltbkvznmiagodxyejwrsuc";
ifstream fin;
char line[80];
int i;
fin.open("crypfile", ios::in | ios::nocreate);
if (!fin)
{
cerr << "Cannot open crypfile!" << endl;
exit(1);
}
// 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] = decryptstr[tolower(line[i])-'a'];
i++;
}
cout << line << endl;
}
}
/*
<Run>
this is a data file that
tests the solution to programming
exercises 2.7 and 2.8.
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?