如何给出文件路径而不是文件名c++?

How to give a file path instead of file name c++?

这段代码部分来自一个简单的md5散列generator.But这里我只能给出一个文件名来生成md5。

LPCWSTR NameOfTheFile = L"Test.txt"; //Name of the file that user is scanning

但是我想在这里给一个文件路径而不是文件名..有什么办法吗?

#include <iostream>
#include <windows.h> 
#include <fstream>
#include <string>

#define BUFSIZE 1024
#define MD5LEN  16


using namespace std;


DWORD main()
{

    MaximizeOutputWindow();

    DWORD cryptStatus = 0;

    BOOL hashResult = FALSE;

    BYTE fileSizeToHash[BUFSIZE];

    HCRYPTPROV cryptProv = 0;

    HCRYPTHASH hash = 0;

    HANDLE file = 0;

    DWORD hashNumbCount = 0;

    DWORD hashRead = 0;

    BYTE getHashValue[MD5LEN];

    CHAR numberConvert[] = "0123456789abcdef"; //hex decimal conversion

    LPCWSTR NameOfTheFile = L"Test.txt"; //Name of the file that user is scanning


    // Logic to check usage goes here.
    file = CreateFile(NameOfTheFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

您可以在 CreateFile 中使用文件路径。试试 NameOfTheFile = L"C:\Text.txt";