问答题
使用VC++6.0打开考生文件夹下的源程序文件2.cpp。请完成函数fun(char *s),使其具有以下功能:
(1)把s中的大写字母转换成小写字母,把其中的小写字母转换成大写字母,并且在函数中调用写函数WriteFile()将结果输出到2.txt文件中。
例如:s="helloWORLD",则结果为“s="HELLOworld"”。
(2)完成函数WriteFile(char *s),把字符串输入文件中。
提示:打开文件使用的第二参数为“ios_base::binary|los_base::app”。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
void WriteFile(char *s)
void fun(char *s)
void ClearFile()
ofstream out1;
out1.open("2.txt");
out1.close();
int main()
ClearFile();
char s[1024];
cout<<"please input a string:"<<end1;
cin.getline(s,1024);
fun(s);
return 0;
【参考答案】
(1)void WriteFile(char *s)中的命令语句:
ofstream out1;
o......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)