Created
          May 16, 2016 05:53 
        
      - 
      
- 
        Save Nathaniel100/73116736d62ce2da209d12c561e1da8a to your computer and use it in GitHub Desktop. 
    Awesome file operation
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | inline bool LoadBinaryFile(const char *name, std::vector<uint8_t> *v) { | |
| std::ifstream ifs(name, std::ifstream::binary); | |
| if(!ifs.is_open()) return false; | |
| ifs.seekg(0, std::ios::end); | |
| (*v).resize(static_cast<size_t>(ifs.tellg())); | |
| ifs.seekg(0, std::ios::beg); | |
| ifs.read(reinterpret_cast<char *>(&(*v)[0]), (*v).size()); | |
| return !ifs.bad(); | |
| } | |
| inline bool SaveBinaryFile(const char *name, const void *data, int size) { | |
| std::ofstream ofs(name, std::ofstream::binary|std::ofstream::trunc); | |
| if(!ofs.is_open()) return false; | |
| ofs.write(reinterpret_cast<const char *>(data), size); | |
| return !ofs.bad(); | |
| } | |
| inline bool FileExists(const char *name) { | |
| std::ifstream ifs(name); | |
| return ifs.good(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment