现在的位置: 首页 > 综合 > 正文

boost 字符串操作

2018年02月08日 ⁄ 综合 ⁄ 共 937字 ⁄ 字号 评论关闭
	#include <boost/xpressive/xpressive_dynamic.hpp>
	using namespace std;
            using namespace boost::xpressive;
	
	//正则表达式
	
	cregex reg = cregex::compile("\\d+",icase);
	assert(regex_match("12",reg));
	boost::xpressive::cmatch what;
	regex_search("1a2,3f",what,reg);
	assert(what.size());

	cout<<what[0]<<endl;
	cout<<what[1]<<endl;

//字符串分割

#include <boost/assign/std/vector.hpp>
#include <boost/algorithm/string.hpp>

int _tmain(int argc, _TCHAR* argv[])
{

string strTemp = "A B  C D E1 F1";
std::vector<string> d;
boost::algorithm::split(d,strTemp,boost::algorithm::is_any_of(" "),boost::algorithm::token_compress_on); //默认参数是 boost::token_compress_off (srTemp  分隔后就是 A B 空 C E1 F1  )
getchar();
return 0;
}

//boost 格式化字符串
方式一  :
cout << boost::format("%s") % "输出内容" << endl;   

方式二 : 
std::string s;  s = str( boost::format("%s") % "输出内容" ); 
    cout << s << endl;   
 
 
方式三 :
   boost::format formater("%s");  formater % "输出内容";  
   std::string s = formater.str();  cout << s << endl;  
   
方式四 : 
    cout << boost::format("%1%") % boost::io::group(hex, showbase, 40) << endl

抱歉!评论已关闭.