The goal of Faker C++ is to provide a library similar to Faker.js for C++ community. Faker C++ is a powerful library designed to streamline the creation of realistic and customizable fake data for testing and development purposes within C++ applications. The use of this library will provide a quick and user-friendly experience for developers, offering a wide variety of modules that cover everything from generating random names and addresses to crafting realistic financial and internet related data.
To properly use Faker C++ you must first assimilate the Faker library (see Consuming Library with CMake).
Once that is done, you need to include the proper header files depending on the module you wish to generate data from. The module header file names can be found by looking in the directory include/faker-cxx
. A list of the functions, their descriptions, and how to use them can be found in docs.
Make sure to include the proper header file that corresponds to the data and subsequent functions you are trying to generate.
Below is an example of how to use Faker C++ in your code.
#include <iostream>
#include "faker-cxx/Date.h"
#include "faker-cxx/Internet.h"
#include "faker-cxx/Location.h"
#include "faker-cxx/String.h"
int main()
{
const auto id = faker::String::uuid();
const auto email = faker::Internet::email();
const auto password = faker::Internet::password();
const auto city = faker::Location::city();
const auto streetAddress = faker::Location::streetAddress();
std::cout << id << std::endl; // 58018063-ce5a-4fa7-adfd-327eb2e2d9a5
std::cout << email << std::endl; // Lois_Hauck@hotmail.com
std::cout << password << std::endl; // @cWLwgM#Knalxeb
std::cout << city << std::endl; // Sayreville
std::cout << streetAddress << std::endl; // 1716 Harriet Alley
return 0;
}
This example generates basic personal information including id, email, password, city, and street address. Users can tailor their data generation by exploring other modules and functions within the library.
- ๐ฉ Airline - aircraft types, airlines, airports, flight numbers
- ๐ผ Animal - animal types and species
- ๐ Book - book title, genre, author, publisher, ISBN
- ๐จ Color - color names, rgb, hex, hcl
- ๐ Commerce - commerce department, product name, sku, price
- ๐ข Company - company name, type, industry, catch phrase, buzz phrase
- ๐ฅ๏ธ Computer - type, manufacturer, model, CPU info, GPU info
- ๐พ Database - column names, column types, database engines
- โน๏ธ Datatype - booleans
- ๐ Date - past, future dates
- ๐ฆ Finance - currency, IBAN, BIC, account name, account number, pin, credit card numbers
- ๐ Food - food category, vegetables, fruits, meats, dishes
- ๐ Git - branch names, commit messages, commit hash
- ๐จโ๐ป Hacker - hacker words
- โ Helper - random element from container
- ๐ Internet - emails, usernames, passwords, IP, HTTP
- ๐ผ๏ธ Image - images urls, github avatar urls, image dimensions
- ๐ Location - countries, cities, zip codes, street addresses
- ๐ Lorem - lorem words, sentences, paragraphs
- ๐ฅ Medicine - conditions, medical tests, specialties
- ๐ฅ Movie - actors, actresses, genres, movie titles
- ๐ถ Music - artists, song names, genres
- ๐ข Number - random integers, floating point numbers
- ๐ง Person - first, last names, job titles, hobby, genders, sex, nationalitiy, language
- ๐ Phone - phone number, IMEI
- โฝ Sport - sport names, athletes, events
- ๐ข String - uuids, alphanumeric, numeric, hexadecimal
- ๐ป System - file paths, file extensions, file names, directories, semantic version
- ๐ฎ Video game - title, genre, platform, studio
- ๐ค๏ธ Weather - temperature, pressure, humidity, weather description
- ๐ฌ Word - sample words, nouns, verbs
-
Add faker to git submodules (execute in project root):
mkdir externals && cd externals git submodule add https://github.com/cieslarmichal/faker-cxx.git git submodule update --init --recursive
-
Link with library:
set(BUILD_FAKER_TESTS OFF) add_subdirectory(externals/faker-cxx) add_executable(main Main.cpp) target_link_libraries(main faker-cxx)
Use one of these compilers when working with Faker C++.
- MSVCโ version 143 or newer.
- GCCโ version 13 or newer.
- Clangโ version 16 or newer.
- Apple Clangโ version 16 or newer.
If you have any confusion please refer to the respective guides.
- GTest (set
BUILD_CONFIG_CXX_TESTS=OFF
CMake flag to disable this dependency) - fmt (only for Apple Clang++ compiler)
We would love it if you contributed to Faker C++! ๐
Whether you are interested in fixing bugs, implementing new features, or improving documentation, your input is welcome and valuable. Before contributing, please review our CONTRIBUTING guide for guidelines on coding standards, making changes, and creating Pull Requests (PRs). Your engagement helps maintain the project's vitality and ensures Faker C++ remains a useful tool for the C++ community.
Additionally, we encourage you to join our Discord Channel for contributors, where you can engage in discussions, seek assistance, and collaborate with fellow developers. Your contributions play a crucial role in the development and furthering of Faker C++. We look forward to your involvement and appreciate your commitment to the project's growth!