SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct TableName
  2. {
  3.     std::string name;
  4.     std::string value;
  5.     int size;
  6.     TableName() : name(), value(), size() {}
  7.     TableName(std::string name, std::string value)
  8.     {
  9.         this->name = name;
  10.         this->value = value;
  11.     }
  12.     TableName(std::string name, std::string value, int s)
  13.     {
  14.         this->name = name;
  15.         this->value = value;
  16.         size = 0;
  17.     }
  18. };
  19.  
  20. bool outputTableName(TableName& tblNm)
  21. {
  22.     std::string plateNumber("12345");
  23.     std::ofstream out(plateNumber, std::ios::binary);
  24.     if (!out) return false;
  25.     size_t sizeName = tblNm.name.size();
  26.     size_t sizeValue = tblNm.value.size();
  27.  
  28.     std::string nameStr = tblNm.name.data();
  29.     std::string valueStr = tblNm.value.data();
  30.    
  31.     out.write(reinterpret_cast<char*>(&sizeName), sizeof(sizeName));
  32.     out.write(reinterpret_cast<char*>(&nameStr), sizeof(sizeName));
  33.  
  34.     out.write(reinterpret_cast<char*>(&sizeValue), sizeof(sizeValue));
  35.     out.write(reinterpret_cast<char*>(&valueStr), sizeof(sizeValue));
  36.     /*const char* nameStr = &tblNm.name.data();
  37.     const char* valueStr = tblNm.value.data();
  38.  
  39.     out.write(nameStr, sizeName);
  40.     out.write(valueStr, sizeValue);*/
  41.     /*out.write(reinterpret_cast<char*>(&tblNm.name), sizeof(tblNm.name));
  42.     out.write(reinterpret_cast<char*>(&tblNm.value), sizeof(tblNm.value));*/
  43.     out.write(reinterpret_cast<char*>(&tblNm.size), sizeof(int));
  44.  
  45.     return true;
  46. }
  47.  
  48. bool inputTableName(TableName& tblNm)
  49. {
  50.     std::string plateNumber("12345");
  51.     std::ifstream in(plateNumber, std::ios::binary);
  52.     if (!in) return false;
  53.  
  54.     size_t sizeName = 0;
  55.     size_t sizeValue = 0;
  56.     in.read(reinterpret_cast<char*>(&sizeName), sizeof sizeName);
  57.     in.read(reinterpret_cast<char*>(&sizeValue), sizeof sizeValue);
  58.  
  59.     char strName[1000];
  60.     char strValue[1000];
  61.     in.read(strName, sizeName);
  62.     in.read(strValue, sizeValue);
  63.  
  64.     /*in.read(reinterpret_cast<char*>(&tblNm.name), sizeof(tblNm.name));
  65.     in.read(reinterpret_cast<char*>(&tblNm.value), sizeof(tblNm.value));*/
  66.     in.read(reinterpret_cast<char*>(&tblNm.size), sizeof(int));
  67.  
  68.     return true;
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top