{"id":13730696,"url":"https://github.com/mutouyun/cpp-format","last_synced_at":"2025-07-10T12:31:07.341Z","repository":{"id":77466521,"uuid":"44905085","full_name":"mutouyun/cpp-format","owner":"mutouyun","description":"C#/Rust/Python style formatting in C++.","archived":false,"fork":false,"pushed_at":"2018-10-23T08:36:32.000Z","size":34,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T21:38:13.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://orzz.org","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mutouyun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-25T10:18:36.000Z","updated_at":"2023-05-12T07:49:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"db5f8897-56c0-4810-bb23-67aac22731e7","html_url":"https://github.com/mutouyun/cpp-format","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutouyun%2Fcpp-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutouyun%2Fcpp-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutouyun%2Fcpp-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mutouyun%2Fcpp-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mutouyun","download_url":"https://codeload.github.com/mutouyun/cpp-format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225637112,"owners_count":17500365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:18.166Z","updated_at":"2024-11-20T22:14:01.706Z","avatar_url":"https://github.com/mutouyun.png","language":"C++","readme":"# A C++ Formatting Library\n\n[![Build Status](https://travis-ci.org/mutouyun/cpp-format.svg?branch=master)](https://travis-ci.org/mutouyun/cpp-format)\n[![Build status](https://ci.appveyor.com/api/projects/status/i9g304g0aen62370/branch/master?svg=true)](https://ci.appveyor.com/project/mutouyun/cpp-format)\n\nC#/Rust/Python style formatting in C++.\n# Compiler Support\n - MSVC-2015  \n - g++-4.8.1(-std=c++1y)  \n - clang-3.4(-std=c++1y)\n\n# License\nCodes covered by the MIT License.\n# Tutorial\nFor using it, you only need to include printf.hpp or output.hpp.  \nSome examples:\n```cpp\n/*\n * printf format string syntax.\n*/\n\nchar c = 'A';\nformat::printf(\"1234567%s%c\\n\", \" \", c);\nformat::printf(std::cout, \"1234567%s%c\\n\", \" \", c);\n\nchar buf[100];\nformat::printf([\u0026buf](const std::string\u0026 str)\n{\n    strcpy(buf, str.c_str());\n}, \"1234567%s%c\\n\", \" \", c);\n\n/*\n * C#/Rust/Python style format string syntax.\n*/\n\nformat::output(\"Hello, World!\\n\");\nformat::output(\"Hello, {0}!\\n\", \"World\");\nformat::output(\"{}, {}, {}, {}\\n\", \"World\", 0, 1, 2);\nformat::output(\"{1}, {}, {0}, {}\", 1, 2); // 2, 1, 1, 2\n\n/*\n * Using format specifier to change your output, just likes std::printf.\n * See: http://www.cplusplus.com/reference/cstdio/printf/\n*/\n\n// 123.321000 123.3 0123 123.3210\nformat::output(\"{0} {1:.1} {2:04.} {3:04.04}\", 123.321, 123.321, 123.321, 123.321);\nformat::output(\"{0} {0:.1} {0:04.} {0:04.04}\", 123.321);\n// address: 0x12345678\nformat::output(\"address: 0x{:08x}\", 0x12345678);\n\n/*\n * You could customize your output to redirect the result to any place.\n*/\n\nstd::string buf;\nauto out = [\u0026buf](std::string\u0026\u0026 str)\n{\n    buf = std::move(str);\n};\nformat::output(out, \"{0}, {1}, {2}, {3}\", 0, 1, 2, 3); // buf = \"0, 1, 2, 3\"\n\n/*\n * It will ignore needless spaces.\n*/\n\n// 123.321000 123.3 0123 123.3210\nformat::output(out, \"{ 0 } {0 \\t : .1} { 0:  04. } { 0 :04.04}\", 123.321);\n\n/*\n * You could output '{' \u0026 '}' for using \"{{\" \u0026 \"}}\".\n*/\n\n// {0, 1}, {2}, 3\nformat::output(out, \"{{{}, {}}}, {{{}}}, {}\", 0, 1, 2, 3);\n\n/*\n * You could output your user-defined type like this:\n*/\n\nclass Foo\n{\npublic:\n    template \u003ctypename T\u003e\n    void operator()(format::follower\u003cT\u003e\u0026\u0026 out) const\n    {\n        out(\"Foo address: 0x{:08x}\", 0x12345678/*(size_t)this*/);\n    }\n} foo;\n// Foo address: 0x12345678, 1, 2, 3\nformat::output(\"{}, {}, {}, {}\", foo, 1, 2, 3);\n\n/*\n * And you could use one format::output to do multiple output.\n*/\n\n// 1 = 1, 2 = 2, 3 = 3\\nfoo = Foo address: 0x12345678\nformat::output(\"1 = {}, \", 1)\n              (\"2 = {}, \", 2)\n              (\"3 = {}\"  , 3).ln() /* Use function \"ln()\" for '\\n' output. */\n              (\"foo = {}\", foo);\n{\n    auto flw = format::output(\"1 = {}\", 1).ln(); // Store a format::follower object.\n    flw(\"2 = {}\", 2).ln();                       // No output here.\n    flw();                                       // Output: 1 = 1\\n2 = 2\\n\n    flw(\"3 = {}\", 3).ln();\n    flw.clear();                                 // The buffer of flw is cleared.\n    flw(\"4 = {}\", 4).ln();\n}   // \u003c-- The flw object has destructed, and output: 4 = 4\\n\n\n/*\n * Any invalid input will throw an exception.\n*/\nEXPECT_THROW(format::printf(\"%s\\n\"    , 123)                , std::invalid_argument);\nEXPECT_THROW(format::printf(\"%d, %s\\n\", 123)                , std::invalid_argument);\nEXPECT_THROW(format::printf(\"%d\\n\"    , 123, \"123\")         , std::invalid_argument);\nEXPECT_THROW(format::output(\"{{}, {}, {{}}, {}\", 0, 1, 2, 3), std::invalid_argument);\nEXPECT_THROW(format::output(\"{}, {}}, {{}}, {}\", 0, 1, 2, 3), std::invalid_argument);\nEXPECT_THROW(format::output(\"{}, {\", 0, 1)                  , std::invalid_argument);\nEXPECT_THROW(format::output(\"{}, {}{}\", 0, 1)               , std::invalid_argument);\nEXPECT_THROW(format::output(\"{}, {}}{}\", 0, 1)              , std::invalid_argument);\nEXPECT_THROW(format::output(\"Hello, {1}!\", \"World\")         , std::invalid_argument);\nEXPECT_THROW(format::output(\"Hello, {0}!\", \"World\", 123)    , std::invalid_argument);\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutouyun%2Fcpp-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmutouyun%2Fcpp-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutouyun%2Fcpp-format/lists"}