mardi 3 mars 2020

How do i pass a variable as wchat_t** from a std::wstring in c++

I am using VS 2019 and the C++ Language Standard is set to Default which I assume is C++ 11?

I have the following constructor of a class in a header file:

input_parser(int& argc, wchar_t** argv)
{
    for (auto i = 0; i < argc; ++i)
    {
        this->tokens_.emplace_back(argv[i]);
    }
};

To call the methods argv parameter I am creating an array of wchar_t in the following manner:

std::wstring command_line = L"-m "F-14RHV" -s "BIT|Flir" -d";
auto buffer = new wchar_t[command_line.length() + 1];
wcsncpy_s(buffer, command_line.length()+1, command_line.c_str(), command_line.length() + 1);
const auto inputs = input_parser(argc, &buffer);
delete[] buffer;

Inside the constructor the first pass when argc == 0 is fine but I get an access violation when argc == 1.

Aucun commentaire:

Enregistrer un commentaire