forked from StrongKs/binaryIO_WarmUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (29 loc) · 937 Bytes
/
main.cpp
File metadata and controls
35 lines (29 loc) · 937 Bytes
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
#include <fstream>
#include <iostream>
using std::string;
int main() {
// Open file in binary input mode
std::fstream file("tips.shp", std::ios_base::binary | std::ios_base::in);
if (!file.is_open()) {
std::cout << "Error opening file" << std::endl;
return 1;
}
unsigned int num_strings;
// TODO: Read number of strings
// Hint: file.read((char *)&num_strings, sizeof(num_strings));
file.read(reinterpret_cast<char*>(&num_strings), sizeof(num_strings));
// TODO: Add loop to:
// 1. Read string length
// 2. Read string characters
// 3. Print string
for (int i = 0; i < num_strings; i++) {
int textsize;
file.read(reinterpret_cast<char*>(&textsize), sizeof(textsize));
char *text = new char[textsize];
file.read(text, textsize);
std::cout << text << std::endl;
delete[] text;
}
file.close();
return 0;
}