-
Notifications
You must be signed in to change notification settings - Fork 0
/
file
65 lines (64 loc) · 1.02 KB
/
file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<fstream>
class File
{
public:
void Display(const char* path)
{
std::ifstream in;
in.open(path);
if (!in.is_open())
{
std::cout << "ERROR";
in.close();
exit(1);
}
file(in);
in.close();
}
virtual void file(std::ifstream& in)
{
std::string str;
in >> str;
std::cout << str << std::endl;
}
};
class ChildFile :public File
{
public:
virtual void file(std::ifstream& in)override
{
std::string str;
in >> str;
for (int i = 0; i < str.length(); ++i)
{
std::cout << '\"' << str[i] << "\" is " << (int)str[i] << std::endl;
}
}
};
class ByteFile:public File
{
public:
virtual void file(std :: ifstream& in)override
{
std::string str;
in >> str;
int num;
for (int i = 0; i < str.length(); ++i)
{
//d = str[i];
//std::cout << '\"'<< str[i]<<"\" is "<< (byte)d<< std::endl;
int num = (int)str[i];
for (int y = 8; y > -1; --y)
{
std::cout << ((str[i]) & 1);
}
std::cout << std::endl;
}
}
};
int main()
{
ByteFile s;
s.Display("h.txt");
}