C++文件操作问题跪求大神!!!

u010233287 2013-10-06 04:37:00
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <stdio.h>
#include "colorcursor.h"
using namespace std;

void explain()
{
setcolor(15);
gotoxy(25,10);
cout << "欢迎使用文本转换程序,请先将待转";
gotoxy(21,11);
cout << "换的文本放在该程序所在目录下!\n";
setcolor();
}


void menu()
{
setcolor(10);
gotoxy(24,7);
cout << "***************菜单***************";
gotoxy(24,9);
cout << " 1: 编码 ";
gotoxy(24,11);
cout << " 2: 解码 ";
gotoxy(24,13);
cout << " 0: 退出 ";
gotoxy(24,15);
cout << "**********************************";
setcolor();
}

void main()
{
char select;
string name, ctrl;
char key[] = "liujian619";
unsigned char ch;
int i = 1;
ifstream infile;
ofstream outfile;

explain();
gotoxy(32,14);
cout << "按任意键继续...";
getch();
system("cls");

menu();
setcolor(15);
gotoxy(24,17);
cout << "输入你的选择:[ ]";
gotoxy(38,17);
select = getche();
while('0' != select && '1' != select && '2' != select)
{
setcolor(12);
gotoxy(20,19);
cout << "\a!!!错误: 输入不合法,请重新输入";
setcolor();
gotoxy(38,17);
select = getche();
}
system("cls");
if('0' == select)
{
return;
}

cout << "待转换文件的文件名:";
cin >> name;

if('2' == select)
{
cout << "输入解码密钥:";
int x = wherex();
int y = wherey();
setcolor(12);
cout << "\n【注意:解码密钥须与编码密钥相同,否则得不到原内容!!!】";
setcolor(15);
gotoxy(x,y);
cin >> key;
cout << "\n\n";
}

infile.open(name.c_str());
if(!infile)
{
cout<<"无法打开!\n";
exit(0);
}
outfile.open("文本转换.txt");
if(!outfile)
{
cout<<"无法打开!\n";
exit(0);
}
outfile << flush;

while(infile >> noskipws >> ch)
{
if('1' == select)
{
ch = ~(ch ^ key[(i%10)-1]);
}
if('2' == select)
{
ch = (~ch) ^ key[(i%10)-1];
}
outfile << ch;
i++;
}

infile.close();
outfile.close();

cout << "转换成功!!!\n";


remove(name.c_str()); //删除文件
rename("文本转换.txt",name.c_str()); //重命名文件
ctrl = "start " + name;
system(ctrl.c_str());
system("pause");
}



接下来几张图片传了半天没传上来,只好给个链接了,希望各位见谅!
http://tieba.baidu.com/p/2634955305
...全文
65 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,633

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧