繁体   English   中英

将char * argv []转换为wstring

[英]Convert char* argv[] to wstring

如何将char* argv[]转换为wstring 我使用"/d"argv获取一个字符串路径,并将其作为我的函数ArrayOfDirContents参数插入。

int main(int argc, char *argv[])
{
    double minimum = 10;
    double input;
    char* filename;
    wstring adr(L".");
    const wchar_t* adresar; 

    adresar = adr.c_str();

    char *p;

    int num;


    errno = 0;
    long conv;

    for (unsigned i = 1; i < argc; i++) {   
        conv = strtol(argv[i], &p, 10);

        // Check for errors: e.g., the string does not represent an integer
        // or the integer is larger than int
        if (errno != 0 || *p != '\0' || conv > INT_MAX) {
            // Put here the handling of the error, like exiting the program with
            // an error message
            cout << "";
        }
        else if(strcmp(argv[1], "/a") == 0) {
            // No error
            num = conv;
            minimum = num;
        }
        else if(strcmp(argv[3], "/d") == 0) {
            int mbtowc(wchar_t* adresar, const char* argv[4], std::size_t n);
        }
        else {
            adresar = adr.c_str();
        }

        getchar();
    }

        string nazev_souboru;
        vector<string> strpole;
        int chyby, l;
        chyby = 0;
        bool vysledek;
        vysledek = ArrayofDirContents(adresar, nazev_souboru, strpole);

        vector<string>::iterator i;

        if (vysledek == true) {
            writeFile(nazev_souboru, strpole, chyby, l, minimum);
            writeSms(strpole, chyby, l, minimum);
            for (i = strpole.begin(); i < strpole.end(); i++) {
                cout << *i;
                cout << '\n';

            }
        }
        //SaveDirectoryContents(L".", nazev_souboru);

}

C:/User部分告诉我您正在使用Windows。 那很重要; 您应该已经提供了该信息。

您无法控制Windows用户名。 它们的格式不能表示为char** argv 替代方法是int wmain(int argc, wchar_t** argv) 这很容易转换为std::vector<std::wstring>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM