mirror of
https://github.com/lucaspalomodevelop/cpp_stuff.git
synced 2026-03-12 22:47:22 +00:00
add write binfile
This commit is contained in:
parent
06f0a80e32
commit
13077375ff
1
write_binfile/inputfile.txt
Normal file
1
write_binfile/inputfile.txt
Normal file
@ -0,0 +1 @@
|
||||
A
|
||||
38
write_binfile/main.cpp
Normal file
38
write_binfile/main.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <bitset>
|
||||
|
||||
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;
|
||||
}
|
||||
5
write_binfile/makefile
Normal file
5
write_binfile/makefile
Normal file
@ -0,0 +1,5 @@
|
||||
dev: compile run
|
||||
compile:
|
||||
g++ -o program main.cpp
|
||||
run:
|
||||
./program
|
||||
1
write_binfile/outputfile.bin
Normal file
1
write_binfile/outputfile.bin
Normal file
@ -0,0 +1 @@
|
||||
01000001
|
||||
BIN
write_binfile/program
Executable file
BIN
write_binfile/program
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user