0

实际上,下面的程序是针对称为 Rabin-IDA 的分散算法的;该算法将数据分成 N 块,然后从 M 块中重新组合(这样M<N)。

因此,下面的程序需要命令行参数,通过项目属性/调试输入。这个参数是文件名,执行的程序将文件分成N个文件,然后从M个分割的文件中重新组合,并将其放在另一个文件中,该文件也应该将其名称作为参数传递。

现在我的问题是,我怎样才能让这个程序通过键盘输入文件名??(我的意思是用户从屏幕输入文件名而不是命令行参数)

下面的代码只是程序的主要功能,它的全部在这个链接(http://www.juancamilocorena.com/home/projects)信息分散算法Rabin-IDA。

#include "include.h"

void __cdecl _tmain(int argc, TCHAR *argv[])
{
DWORD ini=GetTickCount();
try
{
if( argc == 3 ) //recombine
{
RabinIDA rabin=RabinIDA(17,10);
long long size=GetFileSize(argv[1]);
int f[]={0,2,3,5,6,8,9,11,14,15};
rabin.recombine(argv[1],
f,
argv[2],
size);
}
else if(argc == 2)
{
RabinIDA rabin=RabinIDA(17,10);
rabin.split(argv[1]);
}
else
{
printf("Error. To split a file pass a parameter with the file to be splitted\n");
printf("To recombine the file give the name of the original file and the output file\n");
printf("The name of the file is used to get the size of the original file only, in a production\n");
printf("environment the length of the original file and the id of the share must be stored along with the share");
return;
}
printf("%d\n",GetTickCount()-ini);
}
catch (int)
{
PrintLastError(_T("MAIN CATCH"));
}
}
4

1 回答 1

0

如果要从控制台获取文件名,可以这样做:

cout << "Enter file name: ";
string filename;
getline(cin, filename);
于 2013-03-09T11:21:59.253 回答