C++的问题,这里人多所以来这里问了
C++中的文件操作,能通过用户输入文件名,然后找到该文件的函数? 我试过把那用户输入的文件名用字符串变量表示,但是找不到合适的函数打开指定的文件 ,然后操作的
MFC里面好像有,但是我不想用到MFC里面的,有没有除了用MFC里面的类之外的方法?
[ 本帖最后由 清风拂晓 于 2011-6-15 21:10 编辑 ]
程序代码:#include<iostream>
#include<string>
#include<fstream>
#include<conio.h>
using namespace std;
int main()
{
char encryp_filename[100]={0};
//加密文件名
char decrypt_filename[100]={0};
//解密文件名
string password;
//加密、解压的密码
char *p;
//用于逐个字符操作
cout<<"请输入加密文件名"<<endl;
gets(encryp_filename);
gets(decrypt_filename);
ifstream source_file;
//源文件指针
ofstream target_file;
//目标文件指针
source_file.open(encryp_filename,ios::in);
if(!source_file)
{
cout<<"File cannot open"<<endl;
getch();
return 0;
}
p=encryp_filename;
target_file.open(decrypt_filename,ios::trunc);
while(*p!=0)
{
target_file<<*p+5;
p++;
}
source_file.close();
target_file.close();
getch();
return 0;
}
这段自己写的代码,那个用户输入的文件名已事先建立在和该程序的应用程序同一个目录下来了,但还是不行
