Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
88c27ab5
Unverified
Commit
88c27ab5
authored
Jun 18, 2023
by
Dominik Charousset
Committed by
GitHub
Jun 18, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1443
Use load_file instead of reading file manually
parents
23cb4188
c8b9165f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
examples/config/read-json.cpp
examples/config/read-json.cpp
+7
-12
No files found.
examples/config/read-json.cpp
View file @
88c27ab5
...
...
@@ -48,22 +48,17 @@ int caf_main(caf::actor_system& sys) {
// Get file path from config (positional argument).
auto
&
cfg
=
sys
.
config
();
if
(
cfg
.
remainder
.
size
()
!=
1
)
{
std
::
cerr
<<
"*** expected one positional argument: path to a JSON file
\n
"
;
std
::
cerr
<<
"*** expected one positional argument: path to a JSON file
\n
"
<<
"
\n\n
Note: expected a JSON list of user objects. For example:
\n
"
<<
example_input
<<
'\n'
;
return
EXIT_FAILURE
;
}
auto
&
file_path
=
cfg
.
remainder
[
0
];
// Read file into a string.
std
::
ifstream
input
{
file_path
};
if
(
!
input
)
{
std
::
cerr
<<
"*** unable to open input file '"
<<
file_path
<<
"'
\n
"
;
return
EXIT_FAILURE
;
}
std
::
string
json
{
std
::
istreambuf_iterator
<
char
>
{
input
},
std
::
istreambuf_iterator
<
char
>
{}};
// Parse the JSON-formatted text.
// Read JSON-formatted file.
caf
::
json_reader
reader
;
if
(
!
reader
.
load
(
json
))
{
std
::
cerr
<<
"*** failed to parse JSON
input
: "
if
(
!
reader
.
load
_file
(
file_path
))
{
std
::
cerr
<<
"*** failed to parse JSON
file
: "
<<
to_string
(
reader
.
get_error
())
<<
'\n'
;
return
EXIT_FAILURE
;
}
...
...
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