WCHAR[256]作为WCHAR**,即迭代数组字符串与仅迭代一个字符串

WCHAR[256]作为WCHAR**,即迭代数组字符串与仅迭代一个字符串,c,C,我正在编写一段代码,希望迭代字符串数组。但有时我可能需要迭代一个字符串,而这个字符串的形式是WCHAR[256],现在的问题是如何将WCHAR[256]视为LPCWSTR*,以便在迭代时不必将WCHAR[256]视为特例。下面是代码示例 请告诉我这里是否有其他优雅的解决方案 WCHAR BranchName[MAX_PATH]; BOOLEAN AllBranches; WCHAR* DefaultBranches[] = { L"branch1", L"branch2",

我正在编写一段代码,希望迭代字符串数组。但有时我可能需要迭代一个字符串,而这个字符串的形式是WCHAR[256],现在的问题是如何将WCHAR[256]视为LPCWSTR*,以便在迭代时不必将WCHAR[256]视为特例。下面是代码示例

请告诉我这里是否有其他优雅的解决方案

WCHAR BranchName[MAX_PATH];
BOOLEAN AllBranches;

WCHAR* DefaultBranches[] = {
    L"branch1",
    L"branch2",
    L"branch3",
};

INT
wmain (
    _In_ INT Argc,
    _In_ WCHAR **Argv
    )
{

    WCHAR **Branch; // Pointer to array of strings. How can I make this point to WCHAR[256]?
    UINT Count;
    UINT Index;

    ParseArguments(Argc, Argv); // Set AllBranches to true if Custom branch is not provided

    if (AllBranches) {  // If all branches is true
        Branch = DefaultBranches;
        Count = ARRAYSIZE(DefaultBranches);
    } else { // BranchName containing the custom branch name provided as cmd line arg
        // How can BranchName be assigned to Branch pointer so that iterating
        // over just one string do not become a special case?
        Branch =  ???  <-- NOT SURE HOW TO DO IT!!!
        Count = 1;
    }

    // I want this loop to iterate over array string pointers and also with
    // one string
    for (Index = 0; Index < Count; Index += 1) {
        // do some thing with *Branch and I don't want to duplicate it
        // when iterating over array of strings vs iterating over a string
        Branch++;
    }

    return 0;
}
或者


很好。

您是否打算使用WCHAR**DefaultBranchs[]。。。在哪里使用指向宽字符的指针数组?删除“*”更有意义。留下一个指针数组对不起,我已经修好了…我怎样才能把这个指针指向WCHAR[256]?分支=默认分支;很好。它们是类型兼容的。为什么?指针数组被转换为指向访问时的第一个字符串(即WCHAR)的指针**
WCHAR * BranchNameArr [] = { BranchName };
Branch = BranchNameArr;
WCHAR * BranchNamePtr =  BranchName;
Branch = & BranchNamePtr;