diff --git a/write_binfile/inputfile.txt b/write_binfile/inputfile.txt new file mode 100644 index 0000000..8c7e5a6 --- /dev/null +++ b/write_binfile/inputfile.txt @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/write_binfile/main.cpp b/write_binfile/main.cpp new file mode 100644 index 0000000..ea32b6c --- /dev/null +++ b/write_binfile/main.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +std::string string2bin(std::string myString) +{ + std::string binaryString = ""; + for (char &_char : myString) + { + binaryString += std::bitset<8>(_char).to_string(); + } + return binaryString; +} + +int main() +{ + std::fstream Input; + std::ofstream Output("./outputfile.bin", std::ios::in | std::ios::binary); + ; + std::string inputText = ""; + + Input.open("./inputfile.txt"); + // Output.open("./outputfile.dat", std::ios::in | std::ios::binary); // std::ios::in | std::ios::binary + + if (Input.is_open()) + { + while (std::getline(Input, inputText)) + { + std::cout << inputText; + std::string result = string2bin(inputText); + std::cout << result; + Output << result; + } + } + + return 0; +} diff --git a/write_binfile/makefile b/write_binfile/makefile new file mode 100644 index 0000000..9e58628 --- /dev/null +++ b/write_binfile/makefile @@ -0,0 +1,5 @@ +dev: compile run +compile: + g++ -o program main.cpp +run: + ./program \ No newline at end of file diff --git a/write_binfile/outputfile.bin b/write_binfile/outputfile.bin new file mode 100644 index 0000000..07238d9 --- /dev/null +++ b/write_binfile/outputfile.bin @@ -0,0 +1 @@ +01000001 \ No newline at end of file diff --git a/write_binfile/program b/write_binfile/program new file mode 100755 index 0000000..ddeb124 Binary files /dev/null and b/write_binfile/program differ