fmt : C++ formatting library

규규·2024년 3월 11일
0

C++

목록 보기
10/21

fmt 란

  • C++ formatting library
  • Python 과 유사하게 format syntax
  • C++20 부터 std::format 으로 사용 가능

예시

Formatting

#include <fmt/core.h>
#include <iostream>

int main () {
auto str = fmt::format("in {}s\n", 47);
std::cout << str;  // in 47s
}

Printing

#include <fmt/core.h>

int main () {
fmt::print("in {}s\n", 47);  // in 47s
fmt::print(stderr, "error: {}\n", 404);  // error: 404
}

Argument Placeholder

#include <fmt/core.h>

int main () {
int i = 7; 
double d = 3.4;
std::string s = "text";
fmt::print("fast {} output\n", s);
fmt::print("{} times\n", 47);
fmt::print("{} of {}\n", i, 9);
fmt::print("{}|{}|{}\n", d, i, 5);        
fmt::print("escaped {{ & }}\n");
}

출처 :
https://hackingcpp.com/cpp/libs/fmt.html

profile
복습용 저장소

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN