UE4 C++ Android读写配置文件

用了C++的tinyxml库,该XML库支持跨平台。

第一次运行

    TiXmlDocument xdoc;
    if (xdoc.LoadFile((const char*)TCHAR_TO_UTF8(*xfile))) {
    
    
      return FromXml(xdoc.RootElement());
    }
    else {
    
    
      FString s = FString("UConfigComponent::LoadProfile(") + profile + ") failed.";
      return false;
    }

这个配置文件肯定是不存在,但这段代码并不会返回false,实际上会得到一个空的xmldocument。

改进代码如下

  if (FPaths::FileExists(xfile)) {
    
     // 增加判断文件是否存在
    TiXmlDocument xdoc;
    if (xdoc.LoadFile((const char*)TCHAR_TO_UTF8(*xfile))) {
    
    
      return FromXml(xdoc.RootElement());
    }
    else {
    
    
      FString s = FString("UConfigComponent::LoadProfile(") + profile + ") failed.";
      return false;
    }
  }
  else {
    
    
    return false;
  }

很不幸,这段代码也不会返回false。

判断配置读取是否成功,似乎只能判断读取属性是否存在了。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_31042143/article/details/125418768