-1

I want to get the hash files. in current path has 4 files. and it need to hash and save into vector output to perform other task later.

CryptoPP::SHA256 hash;
std::vector<std::string> output;
for(auto& p : std::experimental::filesystem::recursive_directory_iterator(std::experimental::filesystem::current_path()))
{
    if (std::experimental::filesystem::is_regular_file(status(p)))
    {
        CryptoPP::FileSource(p, true, new CryptoPP::HashFilter(hash, new CryptoPP::HexEncoder(new CryptoPP::StringSink(output))), true);
    }
}

for (auto& list : output)
{
    std::cout << list << std::endl;
}
getchar();
return 0;

i get this errors

  1. Description no instance of constructor "CryptoPP::FileSource::FileSource" matches the argument list
  2. Description no instance of constructor "CryptoPP::StringSinkTemplate::StringSinkTemplate [with T=std::string]" matches the argument list
  3. Description 'CryptoPP::StringSinkTemplate::StringSinkTemplate(const CryptoPP::StringSinkTemplate &)': cannot convert argument 1 from 'std::vector>' to 'T &'
  4. Description '': cannot convert from 'initializer list' to 'CryptoPP::FileSource'

`

1 Answers1

2

To reduce your code to its essentials:

std::vector<std::string> output;
FileSource(p, true, new HashFilter(hash, new HexEncoder(new StringSink(output))), true);

The Crypto++ StringSink accepts a reference to a std::string, not a std::vector<std::string>. Also see StringSink in the Crypto++ manual.

The FileSource needs a filename, not a directory name. Given p is a directory iterator and not a file iterator I'm guessing you are going to have additional troubles once you get the name as a C-string or std::string.

You should use something like:

std::vector<std::string> output;
std::string str;
std::string fname = p...;

FileSource(fname.c_str(), true, new HashFilter(hash, new HexEncoder(new StringSink(str))), true);

output.push_back(str);

I have no idea how to get the filename from p, which is a std::experimental::filesystem::recursive_directory_iterator. That's why the code just says std::string fname = p...;.

You should ask another question about filesystem::recursive_directory_iterator. Also see How do you iterate through every file/directory recursively in standard C++?

jww
  • 97,681
  • 90
  • 411
  • 885