https://github.com/esrrhs/printf_vector
like libc printf, but can use vector input
https://github.com/esrrhs/printf_vector
printf vector
Last synced: 10 months ago
JSON representation
like libc printf, but can use vector input
- Host: GitHub
- URL: https://github.com/esrrhs/printf_vector
- Owner: esrrhs
- License: mit
- Created: 2023-04-13T03:44:10.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-14T08:08:20.000Z (over 2 years ago)
- Last Synced: 2025-01-20T22:11:10.890Z (12 months ago)
- Topics: printf, vector
- Language: C++
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# printf_vector
[
](https://github.com/esrrhs/printf_vector)
[
](https://github.com/esrrhs/printf_vector)
[
](https://github.com/esrrhs/printf_vector/actions)
like libc printf, but can use vector input.
modify from [eyalroz/printf](https://github.com/eyalroz/printf) to support vector
* for cpp
* header only
* use std::snprintf
* add namespace
* add vector support
## Usage
the example code is in [main.cpp](./main.cpp)
```cpp
printf_vector::vector_input input;
input.add(1);
input.add(2.2f);
input.add("333");
input.add((void *) 0x4);
input.add(2);
input.add("55555");
input.add(5);
input.add(6);
input.add(1.12345);
const char *fmt = "Hello, World! int=%d float=%f string=%s pointer=%p short-string=%.*s width-int=%*d short-float=%.2f\n";
printf_vector::printfv(fmt, &input);
```
and the output is
```bash
Hello, World! int=1 float=2.200000 string=333 pointer=0000000000000004 short-string=55 width-int= 6 short-float=1.12
```