Getting Started with fmt-display-cpp
Learn how to install, set up, and start using fmt-display-cpp in your projects.
Installation
To get started with fmt-display-cpp, follow these steps to install the library:
# first git clone https://github.com/thefcraft/fmt-display-cpp.git
# Add the fmt library directory
include_directories(path/to/fmt-display-cpp/fmt)
After installation, include the library in your project:
#include "fmt/display.h"
Quick Start Guide
Here's a comprehensive example to get you started with fmt-display-cpp:
#include "fmt/full.h"
#include <vector>
#include <map>
// Custom type output
struct Point { int x, y; };
template<>
struct fmt::Display<Point> {
static std::string print(const Point& p) {
return fmt::format_string("(%d, %d)", p.x, p.y);
}
};
int main() {
// Basic output
fmt::println("Hello, World!");
// Styled output
fmt::println(ansi::green, "Success:", ansi::reset, " Operation completed.");
// Container output
std::vector<int> numbers = {1, 2, 3, 4, 5};
fmt::println("Numbers: ", numbers);
Point p{10, 20};
fmt::println("Point: ", p);
// Complex data structures
std::map<std::string, Point> locations = {
{"Home", {0, 0}},
{"Work", {10, 5}},
{"Park", {-5, 15}}
};
fmt::println("Locations: ", locations);
return 0;
}
This example demonstrates basic output, styled output, container output, custom type output, and handling complex data structures.
Key Concepts
Specialize fmt::Display<T>
for your custom types to control their formatting.
Use ansi::*
constants to add colors and styles to your text.
fmt-display-cpp provides built-in support for printing standard containers like vectors, maps, and sets.
Use fmt::format_string
for type-safe string formatting.
Next Steps
Now that you've got the basics, explore these topics to learn more:
- Learn about Core Features in depth
- Explore Advanced Topics for more complex usage
- Check out the Examples for practical use cases
- Refer to the API Reference for detailed documentation