所以我有这个代码用于检查名为map.spak的crc文件,并将结果与我指定的crc结果进行比较,该结果存储在变量“compare”中
int main(int iArg, char *sArg[])
{
char sSourceFile[MAX_PATH];
memset(sSourceFile, 0, sizeof(sSourceFile));
CCRC32 crc32;
crc32.Initialize(); //Only have to do this once.
unsigned int iCRC = 0;
strcpy(sSourceFile, "map.spak");
int compare = 399857339;
ifstream checkfile(sSourceFile);
if (checkfile){
cout << "Checking file " << sSourceFile << "..." << endl;
crc32.FileCRC(sSourceFile, &iCRC);
if(iCRC == compare){
cout << "File " << sSourceFile << " complete!\nCRC Result: " << iCRC << endl;
}else{
cout << "File " << sSourceFile << " incomplete!\nCRC Result: " << iCRC << endl;
}
}else{
cout << "File not found!" << endl;
}
system("pause");
return 0;
}
现在我想为多个文件制作此代码 假设文件名列表存储在filelist.txt
中filelist.txt结构:
id|filename|specified crc
1|map.spak|399857339
2|monster.spak|274394072
如何进行crc检查,循环每个文件名
我不擅长c ++我只知道一些算法,因为我知道PHP
c ++太复杂了
这是包含CRC源Source Code
的完整来源或者pastebin
TestApp.cpp link
答案 0 :(得分:0)
我对您的代码进行了一些更改。我删除了防护头,因为我们只在头文件中使用它。旧式的memset已被字符串操作所取代。我怀疑你需要将char*
传递给CCRC32对象,因此sSourceFile仍然是const char*
。我用CCRC32编译除了部件之外的代码。
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "../CCRC32.H"
int main(int iArg, char *sArg[])
{
std::vector<std::string> filenames;
// TODO - populate filesnames (paths?)
CCRC32 crc32;
crc32.Initialize(); //Only have to do this once.
for (unsigned int i = 0; i < filenames.size(); i++) {
const char* sSourceFile = filenames[i].c_str();
unsigned int iCRC = 0;
int compare = 399857339; // TODO - you need to change this since you are checking several files
std::ifstream checkfile(sSourceFile);
if (checkfile) {
std::cout << "Checking file " << sSourceFile << "..." << std::endl;
crc32.FileCRC(sSourceFile, &iCRC);
if(iCRC == compare){
std::cout << "File " << sSourceFile << " complete!\nCRC Result: " << iCRC << std::endl;
} else {
std::cout << "File " << sSourceFile << " incomplete!\nCRC Result: " << iCRC << std::endl;
}
} else {
std::cout << "File tidak ditemukan!" << std::endl;
}
}
return 0;
}