C++文件操作问题跪求大神!!!
#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
...全文
相关推荐
C++ 文件操作大全
C++ 文件操作大全,里面列举了几乎所有的C++文件操作以及相关细节。
C++ .h和.cpp文件总结
总结了.h文件能做什么,.cpp文件能做什么,总结了.h文件的本质,方便新手在遇到文件包含、类型声明、变量定义时能理清.h与.cpp关系,纯属个人总结文档。
C++魔方矩阵!!!
C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!C++魔方矩阵!!!
喜欢你!!!.cpp
喜欢你!!!.cpp
C++文件操作工具类
很好的文件操作工具类 好东西要分享


