FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StringNAndBlockStream/BlockStreamAndStringNTest.cpp at master · AmitSna/StringNAndBlockStream · GitHub
AmitSna
StringNAndBlockStream
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
StringNAndBlockStream
/
BlockStreamAndStringNTest.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (29 loc) · 1.19 KB
Breadcrumbs
StringNAndBlockStream
/
BlockStreamAndStringNTest.cpp
Copy path
File metadata and controls
36 lines (29 loc) · 1.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
BlockStreamAndStringNTest.cpp
2015-11-09 - 2018-06-30
Esp. Ing. José María Sola
Profesor
UTN FRBA
*/
#
include
"
BlockStream.h
"
#
include
"
StringN.h
"
#
include
<
iostream
>
//
cout
#
include
<
cassert
>
int
main
(){
struct
Person
{
//
Person: par (int, String de máximo 25 caracteres)
int
id;
String<
25
> name;
//
Sinónimo de array<char,25>
};
constexpr
auto
filename{
"
people
"
};
//
Nombre del archivo de prueba
//
Write
std::ofstream out{filename, std::ios::binary};
//
Crear archivo y conectar flujo en modo binario
WriteBlock
(out, Person{
10
,
PackString
(
"
León
"
)});
//
Escribir en el flujo out una Persona.
out.
close
();
//
Cerrar conexión.
//
Read
std::ifstream in{filename, std::ios::binary};
//
Conectar flujo al archivo existente, en modo binario
Person p;
//
Declarar una persona para almacenar la lectua
ReadBlock
(in, p);
//
Leer del flujo in y guardar en p
in.
close
();
//
Cerrar conexión
remove
(filename);
//
c++17 // std::filesystem::remove(filename); // Remover el archivo de prueba
//
Test: Verificar que leemos lo que habíamos escrito
assert
(
10
== p.
id
);
assert
(
"
León
"
==
UnpackString
(p.
name
) );
}
Back
|
FazBrowse Home
|
New Git URL