How would I create a method like toString() within the SHA-1 class to convert a message digest to a C++ string, each representing a hexadecimal digit.

Also, how could specify whether a file should be read as a text file or binary file?

Thanks

>How would I create a method like toString() within the SHA-1 class
Try using a stringstream with the hex modifier:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
  ostringstream oss;
  char ch = 'a';

  cout<< ch <<" -- "<< hex << static_cast<int> ( ch ) <<endl;
  oss<< ch <<" -- "<< hex << static_cast<int> ( ch );
  cout<< oss.str() <<endl;
}

>how could specify whether a file should be read as a text file or binary file?
Text orientation is the default. If you want binary then add ios::binary or ios_base::binary to the mode:

ifstream in ( filename, ios::binary );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.