【发布时间】:2018-01-14 08:26:17
【问题描述】:
如何将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);
}
【问题讨论】:
-
到目前为止你尝试过什么?您要解决的实际问题是什么? (查找
std::mbtowc。) -
我有一个文件夹路径作为参数,例如“C:/User”,我需要将此字符串从 argv 转换为 wstring 或 const wchar t
-
Martin Bonner 为什么是 mbtowc int?我需要将值保存为 wstring 或 wchart*
-
转换保存在第一个参数提供的缓冲区中。函数结果是转换是否成功。
-
我添加了代码请帮助我