Content of wchar is deleted
我有此代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | JSONObject object; if (value->IsObject()) { object = value->AsObject(); const wchar_t *tmp = from_string(entity_id); std::wcout << tmp << std::endl; std::wcout.flush(); if (object.find(tmp) != object.end()) { std::wcout << tmp << std::endl; std::wcout.flush(); initFromJSON(object[tmp]->AsObject()); } else { return false; } } |
这里的问题是在内部if语句之后,tmp的内容为空。在此之前不是。
当我尝试调试时,一切正常,不会删除内容。但是,当我运行程序时,内容将被删除。知道为什么吗?
方法
1 2 3 4 | std::wstring result; for (int i = 0; i<content.length(); i++) result += wchar_t(content[i]); return result.c_str(); |
方法
1 2 | iterator find(const key_type& __k) {return __tree_.find(__k);} iterator end() _NOEXCEPT {return __tree_.end();} |
我不认为这是find(...)或end()的问题。我猜该问题在其他地方,但我找不到它。因为if语句后wchar的内容为空,所以我不能说
1 | initFromJSON(object[tmp]->AsObject()); |
因为
任何建议我在做什么错?
问题是您的
我完全没有理由将
1 2 3 4 5 6 7 | std::wstring from_entity(...) { std::wstring result; for (int i = 0; i<content.length(); i++) result += wchar_t(content[i]); return result; } |
然后是这个:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | JSONObject object; if (value->IsObject()) { object = value->AsObject(); std::wstring tmp = from_string(entity_id); std::wcout << tmp << std::endl; std::wcout.flush(); if (object.find(tmp.c_str()) != object.end()) { std::wcout << tmp << std::endl; std::wcout.flush(); initFromJSON(object[tmp.c_str()]->AsObject()); } else { return false; } } |
请注意,返回的是