// CMakeProject1.h : Include file for standard system include files,
// or project specific include files.
#pragma once
#include <iostream>
#include <format>
#include <cstdio>
#include <string_view>
// TODO: Reference additional headers your program requires here.
// CMakeProject1.cpp : Defines the entry point for the application.
//
#include "CMakeProject1.h"
using namespace std;
// 实现print函数
template<typename... Args>
void print(const string_view fmt_str, Args && ... args)
{
auto fmt_args{ make_format_args(args...) };
string outstr{ vformat(fmt_str,fmt_args) };
fputs(outstr.c_str(), stdout);
}
int main()
{
// format库现在只在msvc上实现,format() 函数本身返回一个字符串对象
string who{ "everyone" };
cout << format("hello {}\n", who) << endl;
int ival{ 42 };
cout << format("integer value: {}\n", ival) << endl;
double pi{ 3.1415196};
cout << format("pi: {}\n", pi) << endl;
cout << format("hello {1}, {0}", "welcome","there") << endl;// 顺序
cout << format("{:.>10}", ival) << endl;// 十个位,右对齐
cout << format("{:.<10}", ival) << endl;// 左对齐
cout << format("{:.^10}", ival) << endl;
cout << format("pi: {:.5}", pi) << endl;// 精度为5
print("hello {}\n", who);// print 就是 (cout << format)整个过程的实现
return 0;
}