Website Summary Files Commits Branches @commit @diff @stats
path: root / Binary_files
diff options
context:
space:
mode:
Commit0218c678e13e1cb94a352c91733cea68467dc566 (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Files16fb3114cb560242458d10411765e50f5d6183db /Binary_files
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar.gz
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.zip
Parentd4ae0ef9ec1b54420176c4a88e09f2fd44ae31b0 (diff)
start from scratch
diff --git a/Binary_files/BinaryFiles_Cheatsheet.pdf b/Binary_files/BinaryFiles_Cheatsheet.pdf
deleted file mode 100644
index 397177c..0000000
--- a/Binary_files/BinaryFiles_Cheatsheet.pdf
+++ /dev/null
Binary files differ
diff --git a/Binary_files/GetStructsFromBinaryFile.cpp b/Binary_files/GetStructsFromBinaryFile.cpp
deleted file mode 100644
index 011629a..0000000
--- a/Binary_files/GetStructsFromBinaryFile.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-struct test
-{
- char ch;
- int num;
-};
-
-int GetFileSize(ifstream& ifs)
-{
- ifs.seekg(0, std::ios::end); //отиваме в края на файла
- int size = ifs.tellg(); //запазваме коя е текущата позиция(тя всъщност е и размерът на файла)
- ifs.seekg(0, std::ios::beg); //връщаме се в началото на файла
- return size;
-//тази функция е хубаво да я извикваме преди да сме чели каквото и да е от файла, понеже ще се върнем в началото и ще загубим информация до къде сме стигнали с четенето
-}
-
-
-int main()
-{
- std::ifstream inF("Structs.bat", std::ios::binary);
-
- if (!inF.is_open())
- return false;
-
- int fileSize = GetFileSize(inF); // взимаме големината на файла
- int objectCount = fileSize / sizeof(test); // намираме броя на обектите записани във файла
-
- test* arr = new test[objectCount];
-
- inF.read((char*)arr, fileSize); //директно ги четем в масива
-
- if (!inF)
- {
- cout << "Error occurred while reading from the file";
- return 1;
- }
- inF.close();
-
- for (int i = 0; i < objectCount; i++)
- cout << arr[i].ch << " " << arr[i].num << endl;
- delete[] arr;
-
- return 0;
-} \ No newline at end of file
diff --git a/Binary_files/README.md b/Binary_files/README.md
deleted file mode 100644
index ea56a30..0000000
--- a/Binary_files/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# How does the binary file look like?
-The file after running **SaveStructsToBinaryFile.cpp** or **SaveStructsToBinaryFile(as array).cpp**
-
-![Image of the binary file after running the code](https://i.ibb.co/0JthLd6/3-A978-D14-7-C7-A-4-ABD-8-B0-C-DA27-F6-E9-CD0-A.png "Binary file")
-
diff --git a/Binary_files/SaveAndReadStudents_BinaryFile.cpp b/Binary_files/SaveAndReadStudents_BinaryFile.cpp
deleted file mode 100644
index 0f600aa..0000000
--- a/Binary_files/SaveAndReadStudents_BinaryFile.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-void SaveStudent(const char* name, int fn, ofstream& f)
-{
- f.write((const char*)&fn, sizeof(int)); //sizeof(int) is 4
- int strLen = strlen(name);
- f.write((const char*)&strLen,sizeof(int));
- f.write(name, strLen);
-}
-void ReadStudent(ifstream& f)
-{
- int fn;
- f.read((char*)&fn, sizeof(int));
-
- int nameLen;
- f.read((char*)&nameLen, sizeof(int));
-
- char* name = new char[nameLen + 1];
- f.read(name, nameLen);
- name[nameLen] = '\0';
-
- cout << "Name: " << name << " Fn: " << fn << endl;
- delete[] name;
-
-}
-
-
-
-int main()
-{
- //ofstream f;
- // f.open("students.bat");
- // SaveStudent("Ivan",123,f);
- // SaveStudent("Sasho",555,f);
- // f.close();
-
- //ifstream f2;
- //f2.open("students.bat");
- //ReadStudent(f2);
- //ReadStudent(f2);
- //f2.close();
-
-
-
-}
diff --git a/Binary_files/SaveStructsToBinaryFile(as array).cpp b/Binary_files/SaveStructsToBinaryFile(as array).cpp
deleted file mode 100644
index 146a93c..0000000
--- a/Binary_files/SaveStructsToBinaryFile(as array).cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-struct test
-{
- char ch;
- int num;
-};
-
-int main()
-{
-
- test arr[] = { { 'a', 4 }, { 'b', 5 }, { 'c', 6 } };
-
- ofstream outF("Structs.bat", ios::binary);
-
- if (!outF.is_open())
- {
- cout << "Error while opening file" << endl;
- return 1;
- }
-
- outF.write((const char*)&arr, sizeof(arr));
- //можем директно да запазим масива във файла. Резултатът ще същия като от SaveStructToBinaryFile.cpp
-
-
- if (!outF.good())
- {
- cout << "Error occurred while writing the file";
- return 1;
- }
-
- outF.close();
-
- return 0;
-} \ No newline at end of file
diff --git a/Binary_files/SaveStructsToBinaryFile.cpp b/Binary_files/SaveStructsToBinaryFile.cpp
deleted file mode 100644
index 3caad14..0000000
--- a/Binary_files/SaveStructsToBinaryFile.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-struct test
-{
- char ch;
- int num;
-};
-
-int main()
-{
-
- test obj1{ 'a', 4 };
- test obj2{ 'b', 5 };
- test obj3{ 'c', 6 };
-
- ofstream outF("Structs.bat", ios::binary);
-
- if (!outF.is_open())
- {
- cout << "Error while opening file"<<endl;
- return 1;
- }
-
- //запазваме 3-те обекта във файла
- outF.write((const char*)&obj1, sizeof(test));
- outF.write((const char*)&obj2, sizeof(test));
- outF.write((const char*)&obj3, sizeof(test));
-
- if (!outF.good()) // проверяваме дали след операцията потокът е в невалидено състояние
- {
- cout<<"Error occurred while writing the file";
- return 1;
- }
-
- outF.close();
-
- return 0;
-} \ No newline at end of file
diff --git a/Binary_files/Structs.bat b/Binary_files/Structs.bat
deleted file mode 100644
index 37573c8..0000000
--- a/Binary_files/Structs.bat
+++ /dev/null
Binary files differ
diff --git a/Binary_files/StructsBAT (how does it look).png b/Binary_files/StructsBAT (how does it look).png
deleted file mode 100644
index 5e9e5b3..0000000
--- a/Binary_files/StructsBAT (how does it look).png
+++ /dev/null
Binary files differ