Fmt的安装与使用,最主要是吐槽。

安装

本文的编译平台的是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;

}

吐槽

在我的测试项目里面,打印带颜色的字符会出错,向文件写字符也会出错。我在测试项目里面注释掉了,各位可以打开注释自己试一下。不知道是不是我是Window平台下不能使用。有知道的大佬可以在评论留言教我一下。烦的一批啊。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值