Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
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
Libraries
fmt
Commits
4faec5a5
Unverified
Commit
4faec5a5
authored
Jul 05, 2020
by
Victor Zverovich
Committed by
GitHub
Jul 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.rst
parent
7dbc8ac7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
README.rst
README.rst
+24
-15
No files found.
README.rst
View file @
4faec5a5
...
@@ -78,6 +78,13 @@ Print ``Hello, world!`` to ``stdout``:
...
@@ -78,6 +78,13 @@ Print ``Hello, world!`` to ``stdout``:
fmt::print("Hello, world!\n");
fmt::print("Hello, world!\n");
}
}
Format a string:
.. code:: c++
std::string s = fmt::format("The answer is {}.", 42);
// s == "The answer is 42."
Format a string using positional arguments:
Format a string using positional arguments:
.. code:: c++
.. code:: c++
...
@@ -85,27 +92,29 @@ Format a string using positional arguments:
...
@@ -85,27 +92,29 @@ Format a string using positional arguments:
std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
// s == "I'd rather be happy than right."
// s == "I'd rather be happy than right."
Print a chrono duration:
.. code:: c++
#include <fmt/chrono.h>
int main() {
using namespace std::chrono_literals;
fmt::print("Elapsed time: {}", 42ms);
}
prints "Elapsed time: 42ms".
Check a format string at compile time:
Check a format string at compile time:
.. code:: c++
.. code:: c++
// test.cc
// test.cc
#include <fmt/format.h>
#include <fmt/format.h>
std::string s = format(FMT_STRING("{2}"), 42);
std::string s = format(FMT_STRING("{:d}"), "hello");
.. code::
gives a compile-time error because ``d`` is an invalid format specifier for a
string.
$ c++ -Iinclude -std=c++14 test.cc
...
test.cc:4:17: note: in instantiation of function template specialization 'fmt::v5::format<S, int>' requested here
std::string s = format(FMT_STRING("{2}"), 42);
^
include/fmt/core.h:778:19: note: non-constexpr function 'on_error' cannot be used in a constant expression
ErrorHandler::on_error(message);
^
include/fmt/format.h:2226:16: note: in call to '&checker.context_->on_error(&"argument index out of range"[0])'
context_.on_error("argument index out of range");
^
Use {fmt} as a safe portable replacement for ``itoa``
Use {fmt} as a safe portable replacement for ``itoa``
(`godbolt <https://godbolt.org/g/NXmpU4>`_):
(`godbolt <https://godbolt.org/g/NXmpU4>`_):
...
...
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