我想从字符串转换为整数,所以我在winapi中使用了atoi(),如下所示。 当我使用atoi功能时,我遇到了这个错误信息
//just promisifying `lookup.getChildrenAsCallback`
function getChildrenAsPromise(path){
return new Promise(function(resolve, reject){
lookup.getChildrenAsCallback(path, function(err, children) {
if(err) reject(err);
else resolve(children);
});
})
}
//basically the resucrive version of `getChildrenAsPromise`
function nodeSearch(path) {
//get the direct children for this path
return getChildrenAsPromise(path)
//then run the recursion, get their descendants
.then(function(nodes){
return Promise.all(nodes.map(function(node){
//the recursive part
return nodeSearch(path + "/" + node);
}))
})
//then flatten the result and prepend the current path
.then(function(children){
//children is actually an array of arrays
//so we need to flatten it.
var p = [ path ];
return p.concat.apply(p, children);
});
}
如何将字符串转换为整数?
1>d:\work\usb\isp1\isp1\source1.cpp(771): error C2664: 'int atoi(const char *)' : cannot convert argument 1 from 'wchar_t [5]' to 'const char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
答案 0 :(得分:0)
atoi
用于const char *
个字符串;你拥有的是wchar_t
字符串。 char
和wchar_t
不可互换。使用wchar_t
字符串的相应函数; _wtoi
:
ii = _wtoi(str_a);
iii = _wtoi(str_d);