Mira2706

neshtosi

Jun 12th, 2020
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. //File.h
  2.  
  3. #ifndef FILE_H
  4. #define FILE_H
  5. #include "./String.h"
  6.  
  7.  
  8. class File
  9. {
  10.  
  11.     public:
  12.         String filePath;
  13.         File();
  14.         void open(String filePath);
  15.         void close();
  16.         void save();
  17.         void saveAs();
  18.         void help();
  19.         void exit();
  20.         ~File();
  21.  
  22.     protected:
  23.  
  24.     private:
  25. };
  26.  
  27. //String.h
  28.  
  29. #endif // FILE_H
  30.  
  31. #ifndef STRING_H
  32. #define STRING_H
  33.  
  34.  
  35. class String
  36. {
  37.     public:
  38.     String();
  39.     String(const char *s);
  40.     String operator+(String other);
  41.     String& operator=(const String& other);
  42.     bool operator==(String other);
  43.     const char* getStr()const;
  44.     ~String();
  45.  
  46.     private:
  47.     char* str;
  48. };
  49.  
  50. #endif // STRING_H
  51.  
  52. //File.cpp
  53. #include "../include/File.h"
  54. #include <fstream>
  55. #include "../include/String.h"
  56.  
  57. File::File()
  58. {
  59. }
  60.  
  61. public:
  62. String filePath;
  63.         open(String filePath);
  64.         String str;
  65.         String filePath;
  66.     ofstream table(filePath);
  67. String line;
  68.  
  69.     while (std::getline(filePath, line))
  70.     {
  71.         std::istringstream iss(line);
  72.        std:: cout << iss << std::endl;
  73.        // if (!(iss >> a >> b)) { break; } // error
  74.  
  75.         // process pair (a,b)
  76.     }
  77.  
  78. void File::close();
  79. void File::save();
  80. void File::saveAs();
  81. void File:: help();
  82. void File:: exit();
  83.  
  84. File::~File()
  85. {
  86. //dtor
  87. }
  88. //String.cpp
  89. #include "String.h"
  90.  
  91. String::String()
  92. {}
  93. String::String(const char *s)
  94. {
  95.     str = new char[strlen(s)+1];
  96.     strcpy(str, s);
  97. }
  98.  
  99. String String::operator+(String other)
  100. {
  101.     String result;
  102.     result.str = new char[strlen(str)+strlen(other.str)+1];
  103.     strcpy(result.str, str);
  104.     strcat(result.str, other.str);
  105.     return result;
  106. }
  107. String& String::operator=(const String& other)
  108. {
  109.     delete[] str;
  110.     str = new char(strlen(other.str)+1);
  111.     strcpy(str, other.str);
  112.     return *this;
  113. }
  114.  
  115. bool String::operator==(String other)
  116. {
  117.     if(strcmp(str, other.str) == 0)
  118.         return true;
  119.     else
  120.         return false;
  121. }
  122. const char* String::getStr()const
  123. {
  124.     return str;
  125. }
  126.  
  127.  
  128. String::~String()
  129. {
  130.     delete[] str;
  131. }
  132. std::ostream& operator<<(std::ostream& os, String other)
  133. {
  134.     os << other.getStr();
  135.     return os;
  136. }
  137. //main
  138. #include <iostream>
  139. #include "./include/String.h"
  140. #include "./include/File.h"
  141. #include <cstring>
  142.  
  143. using namespace std;
  144.  
  145. int main()
  146. {
  147.     //File Table;
  148.     int test = 123456789;
  149.  
  150. //    std::cin >> Table.filePath;
  151.     std::cout << test;
  152.     //Table.open(Table.filePath);
  153.  
  154.     return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment