基础知识之C++篇

//-----------------------------------------------------------------
// 计算 hash 值,返回的 hash 值数据类型是 uint64_t
#include <iostream>
#include <string>
#include <functional>
 
int main()
{
    std::string s = "Stand back! I've got jimmies!";
    std::cout << std::hash<std::string>{}(s) << ' ';
}
 
//-----------------------------------------------------------------------------
// 功能1:给字符串添加双引号和斜杠
// 功能2:剔除字符串中的双引号和斜杠
#include <iostream>
#include <iomanip>
#include <sstream>
 
int main()
{
    std::stringstream ss;
    std::string in = "String with spaces, and embedded "quotes" too";
    std::string out;
 
    // 给字符串添加双引号和斜杠
    ss << std::quoted(in);

    // 剔除字符串中的双引号和斜杠
    ss >> std::quoted(out);
}
//----------------------------------------------------------------------------
// std::setw() 设置缩进字符数量
// std::setfill() 设置缩进字符
std::cout << std::setw(4<< j_object << " ";
std::cout << std::setw(2<< j_array << " ";
std::cout << std::setw(1<< std::setfill(' '<< j_object << " ";
 
//----------------------------------------------------------------------------
// 获取 CPU 硬核数量
int max_thread_num = std::thread::hardware_concurrency();

原文地址:https://www.cnblogs.com/micemik/p/12254635.html