我看到一个奇怪的失败,dynamic_cast它NULL在clang编译器上返回.但是相同的代码正在使用gcc环境.
你能指点我可能是根本原因吗?dynamic_castllvm和gcc 之间有什么区别?
我正在使用编译器的默认行为,我认为默认情况下启用RTTI.
template<typename T> T*
find_msg_of_type(
MsgList *list
) {
T* msg = NULL;
if (list) {
for (std::vector<MsgList*>::iterator it = list->element.begin();
it != list->element.end();
it++) {// MsgList can be list of objects build with GSoap.
if (typeid(*(*it)) == typeid(T)) {
msg = dynamic_cast<T*>(*it); // Failing on clang but this same code is working with gcc compiler.
break;
}
}
}
return msg;
}
Run Code Online (Sandbox Code Playgroud)
还有一个观察:用gcc
if (typeid(*(*it)) == typeid(T))
Run Code Online (Sandbox Code Playgroud)
正如预期的那样完美地工作但是有铿锵声
if (typeid(*(*it)) …Run Code Online (Sandbox Code Playgroud) 我想写一个std::wstring文件,需要读取该内容std:wstring.当字符串为时,会发生这种情况L"<Any English letter>".但是当我们有像孟加拉语,卡纳达语,日语等字符,任何类型的非英语字母时,问题就出现了.试过各种选择,如:
std::wstring为std::string写入文件并将读取时间读取为std::string转换为std::wstring
std::wstringwofstream,这对于母语字母也没有帮助 std::wstring data = L"?????? ?????????";平台是mac和Linux,语言是C++
码:
bool
write_file(
const char* path,
const std::wstring data
) {
bool status = false;
try {
std::wofstream file(path, std::ios::out|std::ios::trunc|std::ios::binary);
if (file.is_open()) {
//std::string data_str = convert_wstring_to_string(data);
file.write(data.c_str(), (std::streamsize)data.size());
file.close();
status = true;
}
} catch (...) {
std::cout<<"exception !"<<std::endl;
}
return status;
}
// Read Method
std::wstring
read_file(
const char* filename
) …Run Code Online (Sandbox Code Playgroud)