FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp_tests/t14_vector_data.cpp at master · s-kramer/cpp_tests · GitHub
s-kramer
/
cpp_tests
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp_tests
/
t14_vector_data.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (57 loc) · 1.53 KB
Breadcrumbs
cpp_tests
/
t14_vector_data.cpp
Copy path
File metadata and controls
74 lines (57 loc) · 1.53 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
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
66
67
68
69
70
71
72
73
#
include
<
iostream
>
#
include
<
cstdlib
>
#
include
<
boost/scoped_ptr.hpp
>
#
include
<
fcntl.h
>
#
include
<
cstdio
>
#
include
<
vector
>
#
include
<
time.h
>
int
open_file
(
const
char
* path =
"
scoped_ptr_test
"
)
{
int
f =
open
(path,
O_RDWR
|
O_NONBLOCK
);
if
(f <
0
)
{
perror
(
"
File opening went bad.
\n
"
);
}
return
f;
}
int
main
()
{
//
boost::scoped_ptr<unsigned int> p ( new unsigned int (5));
//
//
alternative vector test
//
//
int values_array[] = {5, 16, 55, 123, 222};
//
std::vector<unsigned int> p (values_array, values_array + sizeof (values_array) / sizeof (int));
std::vector <
unsigned
int
>
p
(
10
);
unsigned
int
* p_data = p.
data
();
auto
iterator = p.
begin
();
for
(
auto
& i : p)
i =
rand
() %
1000
;
ssize_t
ret =
0
;
int
f =
open_file
();
ret =
write
(f, &(*iterator), p.
size
() *
sizeof
(
unsigned
int
));
p_data += ret /
sizeof
(
unsigned
int
);
//
moves the pointer to unwritten data
if
(ret <
0
)
{
perror
(
"
Write error.
"
);
return
ret;
}
else
std::cout <<
"
Write status:
"
<< ret <<
'
\n
'
;
close
(f);
f =
open_file
();
ret =
read
(f, p.
data
(), p.
size
() *
sizeof
(
unsigned
int
));
if
(ret <
0
)
{
perror
(
"
Read error.
"
);
return
ret;
}
else
std::cout <<
"
Read status:
"
<< ret <<
'
\n
'
;
for
(
auto
& i : p)
std::cout << i <<
"
"
<< &i <<
'
\n
'
;
for
(
auto
i = p.
begin
(); i != p.
end
(); ++i)
std::cout << &(*i) <<
"
"
<< *i <<
'
\n
'
;
close
(f);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL