安装
本文的编译平台的是VS2015 与Cmake.
1、打开Cmake,在1处选择下载的源码,
2、在2处选择生成文件所放在的位置。需要自己在目录下新建build文件夹。
3、点击3处生成配置。注意第一次点击的时候会出现一个对话框,让你选择编译平台。我选的是VS2015 X64平台。默认不选的话会是x86的。
4、第一次点击3处按钮可能会出现红色的,如图所示。再点击一次3处按钮。
5、点击4处按钮,在build文件夹生成项目文件。
6、点击下面的fmt项目,右键重新生成,生成库文件,注意是release还是debug模式,根据需要自己选择。
7、至此,库文件生成成功,将头文件与库文件连接好在别的项目就可以使用。
使用
部分使用情况
#include <iostream>
#include <vector>
#include <string>
#include "fmt/ranges.h"
#include "fmt/core.h"
#include "fmt/color.h"
#include "fmt/chrono.h"
#include "fmt/os.h"
#include "fmt/printf.h"
#include "fmt/compile.h"
#include "fmt/locale.h"
//#include "fmt/posix.h"
// 使用 memory_buffer 包含的头文件
#include "fmt/format.h"
/*
静态库必须这么写
*/
#ifndef _WIN64
#ifdef _DEBUG
#pragma comment(lib, "../lib32/debug/fmtd.lib")
#else
#pragma comment(lib, "../lib32/release/fmt.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib, "../lib64/debug/fmtd.lib")
#else
#pragma comment(lib, "../lib64/release/fmt.lib")
#endif
#endif
// _a前缀必须引用的命名空间
using namespace fmt::literals;
/*
参考文档
https://www.cnblogs.com/pandamohist/p/13362139.html
*/
int main()
{
//fmt::print("Hello, world!\n");
/*std::vector<int> v = { 1, 2, 3 };
fmt::print("{}\n", v);*/
/*using namespace std::literals::chrono_literals;
fmt::print("Default format: {} {}\n", 42s, 100ms);
fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);*/
//std::string s = fmt::format("The answer is {}.", 42);
//std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
//fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,"Hello, {}!\n", "world");
/*fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
fmt::emphasis::underline, "Hello, {}!\n", "мир");*/
//fmt::print(fg(fmt::rgb(255,20,30)),"Hello, {}!\n", "世界");
//fmt::ostream::output_file();
/*auto out = fmt::output_file("guide.txt");
out.print("Don't {}", "Panic");*/
// 1、fmt::format 返回一个字符串
/*auto str = fmt::format("1、{0} = {1}\n\n", "1+1", 2);
std::cout << str << std::endl;*/
// 2、使用 fmt::memory_buffer 可以避免构造使用string
/*
// 使用 memory_buffer 包含的头文件
#include "3rd_part/fmt/format.h"
*/
//fmt::memory_buffer out;
//format_to(out, "2、For a moment, {} happened.\n\n", "nothing");
这里输出的也是一个char字符串
//fmt::print(out.data());
//auto err_no = 1;
//fmt::print(stderr, "3、System error code = {}\n\n", err_no);
//fmt::print("3、Don't {}\n\n", "panic");
//fmt::print("4、I'd rather be {1} than {0}.\n\n", "right", "happy");
//fmt::print("5、Hello, {name}! The answer is {number}. Goodbye, {name}.\n\n",
// fmt::arg("name", "World"),
// fmt::arg("number", 99));
///*
//若编译器支持c++ 11用户自定义的文本, 后缀 _a提供了一种可以选。
//*/
//fmt::print("6、Hello, {name}! The answer is {number}. Goodbye, {name}.\n\n",
// "name"_a = "World",
// "number"_a = 42);
// fmt::print(fmt::format(L"Cyrillic letter {}", L'\x42e'));
fmt::print(bg(fmt::terminal_color::cyan), "tcyan");
//fmt::print(fg(fmt::rgb(10, 50, 63)), "hello {}\n", "world");
//fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
//fmt::emphasis::underline, "Hello, {}!\n", "мир");
//fmt::print(fg(fmt::rgb(255, 20, 30)), "Hello, {}!\n", "世界");
system("pause");
return 0;
}