boost库

 boost's msdn  http://theboostcpplibraries.com/index
#include <conio.h>
#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
using namespace std;

void test002()
{
	typedef boost::tokenizer<boost::char_separator<wchar_t>,std::wstring::const_iterator, std::wstring> tokenizer;

	std::wstring s = L"Boost C++ Libraries android androfuck ";

	boost::char_separator<wchar_t> sep(L" ");
	tokenizer tok(s, sep);
	for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
		std::wcout << *it <<std::endl;
}
void test001()
{

	typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
	std::string s = "Boost C++ Libraries test 中文 fuck android andfff ";
	//boost::char_separator<char> sep(" ");
	boost::char_separator<char> sep("and"," ");
	//boost::char_separator<char> sep{" ", "+", boost::keep_empty_tokens};
	tokenizer tok(s,sep);
	for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
		std::cout << *it <<std::endl;
}
//http://theboostcpplibraries.com/boost.tokenizer
int main(int argc, char* argv[])
{

	test002();
	
	getch();
}
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
#include <conio.h>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>

using namespace boost::uuids;
using namespace boost::algorithm;

//http://theboostcpplibraries.com/boost.stringalgorithms
int main()
{
	random_generator gen;
	uuid id = gen();
	std::string ss = to_string(id);
	std::cout << ss << '\n';
	std::cout << boost::lexical_cast<std::string>(id) << '\n';

	std::string s = "Boost C++ Libraries";
	std::cout << to_upper_copy(s) << '\n';

	std::cout.setf(std::ios::boolalpha);
	std::cout << starts_with(s, "Boost") << '\n';
	std::cout << ends_with(s, "Libraries") << '\n';
	std::cout << contains(s, "C++") << '\n';
	std::cout << lexicographical_compare(s, "Boost") << '\n';


	std::vector<std::string> v;
	split(v, s, is_space());
	std::cout << v.size() << '\n';
	for (int i=0;i<v.size();i++)
	{
	
		std::cout<<v.at(i)<<std::endl;
	}

	boost::iterator_range<std::string::iterator> r =find_regex(s, boost::regex("\\w\\+\\+"));
	std::cout <<"regex="<< r << '\n';

	std::string s3 = "123456789Boost C++ Libraries123456789";
	std::cout << trim_left_copy_if(s3, is_digit()) << '\n';
	std::cout << trim_right_copy_if(s3, is_digit()) << '\n';
	std::cout << trim_copy_if(s3, is_digit()) << '\n';

	std::string s4 = "\t Boost C++ Libraries \t";
	std::cout << "_" << trim_left_copy(s4) << "_\n";
	std::cout << "_" << trim_right_copy(s4) << "_\n";
	std::cout << "_" << trim_copy(s4) << "_\n";
	
	std::string s5 = "Boost C++ Libraries";
	std::cout << replace_first_copy(s5, "+", "-") << '\n';
	std::cout << replace_nth_copy(s5, "+", 0, "-") << '\n';
	std::cout << replace_last_copy(s5, "+", "-") << '\n';
	std::cout << replace_all_copy(s5, "+", "-") << '\n';
	std::cout << replace_head_copy(s5, 5, "BOOST") << '\n';
	std::cout << replace_tail_copy(s5, 9, "LIBRARIES") << '\n';

	
	//std::string s = "Boost C++ Libraries";
	boost::iterator_range<std::string::iterator> r2 = find_first(s, "C++");
	std::cout << r2 << '\n';
	r2 = find_first(s, "xyz");
	std::cout << r2 << '\n';


	//std::string s = "Boost C++ Libraries";
	std::cout << erase_first_copy(s, "s") << '\n';
	std::cout << erase_nth_copy(s, "s", 0) << '\n';
	std::cout << erase_last_copy(s, "s") << '\n';
	std::cout << erase_all_copy(s, "s") << '\n';
	std::cout << erase_head_copy(s, 5) << '\n';
	std::cout << erase_tail_copy(s, 9) << '\n';

	getch();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值