#include<iostream>
#include<fstream>
using namespace std;
void set_w()//输入字符,保存到磁盘
{
ofstream outf;
outf.open("dat1.txt", ios::out);
char a[10];
for (int i = 0; i < 10; i++)
{
cin >> a[i];
outf << a[i];
}
outf.close();
}
void show_w()//读取字符,显示刚才保存的文件
{
char b[10];
ifstream inf;
inf.open("dat1.txt", ios::in);
for (int i = 0; i < 10; i++)
{
inf >> b[i];
cout << b[i]<<" ";
}
inf.close();
}
void change_w()//将刚才的字符大写改成小写,小写改成大写,,保存到d[]里面
{
char c[10],d[10];
ifstream inf2;
inf2.open("dat1.txt", ios::in);
for (int i = 0; i < 10; i++)
{
inf2 >> c[i];
if (c[i] >= 65 && c[i] <= 90)
{
d[i] = c[i] + 32;
}
if (c[i] >= 97 && c[i] <= 122)
{
d[i] = c[i] - 32;
}
}
inf2.close();
ofstream outf2;//对改写后的字符保存到磁盘,命名为“dat2.txt”
outf2.open("dat2.txt", ios::out);
for (int i = 0; i < 10; i++)
{
outf2<< d[i] << " ";
}
outf2.close();
}
int main()
{
set_w();
show_w();
change_w();
return 0;
}
#include<fstream>
using namespace std;
void set_w()//输入字符,保存到磁盘
{
ofstream outf;
outf.open("dat1.txt", ios::out);
char a[10];
for (int i = 0; i < 10; i++)
{
cin >> a[i];
outf << a[i];
}
outf.close();
}
void show_w()//读取字符,显示刚才保存的文件
{
char b[10];
ifstream inf;
inf.open("dat1.txt", ios::in);
for (int i = 0; i < 10; i++)
{
inf >> b[i];
cout << b[i]<<" ";
}
inf.close();
}
void change_w()//将刚才的字符大写改成小写,小写改成大写,,保存到d[]里面
{
char c[10],d[10];
ifstream inf2;
inf2.open("dat1.txt", ios::in);
for (int i = 0; i < 10; i++)
{
inf2 >> c[i];
if (c[i] >= 65 && c[i] <= 90)
{
d[i] = c[i] + 32;
}
if (c[i] >= 97 && c[i] <= 122)
{
d[i] = c[i] - 32;
}
}
inf2.close();
ofstream outf2;//对改写后的字符保存到磁盘,命名为“dat2.txt”
outf2.open("dat2.txt", ios::out);
for (int i = 0; i < 10; i++)
{
outf2<< d[i] << " ";
}
outf2.close();
}
int main()
{
set_w();
show_w();
change_w();
return 0;
}