Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
11756238
Commit
11756238
authored
Jul 09, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the csv io manipulator that lets you print a matrix in cvs format.
parent
a97b5794
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
matrix.h
dlib/matrix/matrix.h
+45
-0
No files found.
dlib/matrix/matrix.h
View file @
11756238
...
...
@@ -1813,6 +1813,51 @@ namespace dlib
This function is defined inside the matrix_read_from_istream.h file.
*/
// ----------------------------------------------------------------------------------------
class
print_matrix_as_csv_helper
{
/*!
This object is used to define an io manipulator for matrix expressions.
In particular, this code allows you to write statements like:
cout << csv << yourmatrix;
and have it print the matrix with commas separating each element.
!*/
public
:
print_matrix_as_csv_helper
(
std
::
ostream
&
out_
)
:
out
(
out_
)
{}
template
<
typename
EXP
>
std
::
ostream
&
operator
<<
(
const
matrix_exp
<
EXP
>&
m
)
{
for
(
long
r
=
0
;
r
<
m
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
if
(
c
+
1
==
m
.
nc
())
out
<<
m
(
r
,
c
)
<<
"
\n
"
;
else
out
<<
m
(
r
,
c
)
<<
", "
;
}
}
return
out
;
}
private
:
std
::
ostream
&
out
;
};
class
print_matrix_as_csv
{};
const
print_matrix_as_csv
csv
;
inline
print_matrix_as_csv_helper
operator
<<
(
std
::
ostream
&
out
,
const
print_matrix_as_csv
&
)
{
return
print_matrix_as_csv_helper
(
out
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment