1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      2C++Boost容器-創(chuàng)新互聯(lián)

      C++ Boost 2 容器

      創(chuàng)新互聯(lián)是專(zhuān)業(yè)的太原網(wǎng)站建設(shè)公司,太原接單;提供做網(wǎng)站、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行太原網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

      2 C++ Boost  容器

      在線文檔:http://www.boost.org/doc/

      離線文檔:解壓Boost壓縮包,瀏覽boost_1_62_0/boost_1_62_0/libs/libraries.htm#Containers

      目錄:
      Boost any 容器
      引用與指針復(fù)習(xí),引用并不會(huì)退化
      boost.tuple,類(lèi)似STL的pair鍵值對(duì),但是tuple可以裝10種不同的任意數(shù)據(jù)類(lèi)型
      tuple的創(chuàng)建,值操作要注意的
      tuple.tie:創(chuàng)建一個(gè)所有元素類(lèi)型為非const引用的tuple
      tuple IO設(shè)定輸出格式,只接受固定格式的輸入
      
      Boost.array
      Boost.unordered  無(wú)序數(shù)據(jù)插入
      Boost,unordered hash_map桶的分布情況
      Boost:Multi-Array 多維數(shù)組
      Boost 多維數(shù)組,
      Boost.Property Map  Key,value
      
      Property Tree 解析XML文件
      Property Tree 生成XML文件
      Property Tree 解析JSON文件
      Property Tree 生成JSON文件

      Boost any 容器

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      
      using boost::any_cast;
      typedef std::list many;
      
      void append_int(many & values, int value)
      {
          boost::any to_append = value;
          values.push_back(to_append);
      }
      
      void append_string(many & values, const std::string & value)
      {
          values.push_back(value);
      }
      
      void append_char_ptr(many & values, const char * value)
      {
          values.push_back(value);
      }
      
      void append_any(many & values, const boost::any & value)
      {
          values.push_back(value);
      }
      
      void append_nothing(many & values)
      {
          values.push_back(boost::any());
      }
      bool is_empty(const boost::any & operand)
      {
          return operand.empty();
      }
      
      bool is_int(const boost::any & operand)
      {
          return operand.type() == typeid(int);
      }
      
      bool is_char_ptr(const boost::any & operand)
      {
          try
          {
              any_cast(operand);
              return true;
          }
          catch(const boost::bad_any_cast &)
          {
              return false;
          }
      }
      
      bool is_string(const boost::any & operand)
      {
          return any_cast(&operand);
      }
      
      void count_all(many & values, std::ostream & out)
      {
          out << "#empty == "        << std::count_if(values.begin(), values.end(), is_empty) << std::endl;
          out << "#int == "          << std::count_if(values.begin(), values.end(), is_int) << std::endl;
          out << "#const char * == " << std::count_if(values.begin(), values.end(), is_char_ptr) << std::endl;
          out << "#string == "       << std::count_if(values.begin(), values.end(), is_string) << std::endl;
      }
      int main()
      {
      	many m1;
      	append_int(m1,128);
      	append_int(m1,65535);
      	append_char_ptr(m1,"Hello");
      	append_string(m1,"Hello");
      	append_nothing(m1);
      	count_all(m1,std::cout);
      }
      
      chunli@Linux:~/boost$ g++ main.cpp -Wall && ./a.out
      #empty == 1
      #int == 2
      #const char * == 1
      #string == 1
      chunli@Linux:~/boost$

      引用與指針復(fù)習(xí),引用并不會(huì)退化

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      
      void fun1(int (&a)[20])
      {
      	std::cout << sizeof(a) << std::endl;
      	std::cout << a[0] << std::endl;
      	std::cout << a[1] << std::endl;
      }
      
      void fun2(int *a)
      {
      	std::cout << a[0] << std::endl;
      	std::cout << a[1] << std::endl;
      }
      int main()
      {
      	int a[20];
      	a[0] = 1;
      	a[1] = 111;
      	fun1(a);
      	fun2(a);
      	return 0;
      }
      
      chunli@Linux:~/boost$ g++ main.cpp -Wall && ./a.out
      80
      1
      111
      1
      111
      chunli@Linux:~/boost$

      boost.tuple,類(lèi)似STL的pair鍵值對(duì),但是tuple可以裝10種不同的任意數(shù)據(jù)類(lèi)型

      tuple的創(chuàng)建,值操作要注意的

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      
      class A{};
      
      int main()
      {
      	using boost::tuple;
      
      	double d = 2.7;
      	A a;
      	tuple t(1,d,a);	//創(chuàng)建tuple對(duì)象
      
      	++boost::get<0>(t);
      	int i = boost::get<0>(t);
      	i = t.get<0>();
      	boost::get<0>(t) = 5;
      	A aa = boost::get<2>(t);  	//接收對(duì)象
      	//A aa = boost::get<3>(t);  	//下標(biāo)溢出
      	double e = boost::get<1>(t); 	//數(shù)據(jù)類(lèi)型自動(dòng)轉(zhuǎn)換
      	boost::get<1>(t) = 3.14;	//修改值
      	//boost::get<2>(t) = "hello";	//數(shù)據(jù)類(lèi)型不匹配
      
      
      	const tuple ct = t;//創(chuàng)建tuple對(duì)象
      	int j = boost::get<0>(ct);
      	//boost::get<0>(ct) = 5;//無(wú)法修改 const數(shù)據(jù)類(lèi)型
      
      
      
      	return 0;
      }
      
      chunli@Linux:~/boost$ g++ main.cpp  && ./a.out
      chunli@Linux:~/boost$

      tuple.tie:創(chuàng)建一個(gè)所有元素類(lèi)型為非const引用的tuple

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      
      int main()
      {
      	int i;
      	char c;
      	double d;
      	
      	boost::tie(i,c,d);	//通過(guò)boost::tuple 來(lái)修改
      	boost::tie(i,c,d) = boost::tuple(1,'A',3.1415926);
      	std::cout<

      tuple IO設(shè)定輸出格式,只接受固定格式的輸入

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      using namespace std;
      int main()
      {
      //輸出
      	//默認(rèn)輸出 (1 602214129 Hello Boost!)
      	boost::tuple a(1.0f,602214129,string("Hello Boost!"));
      	cout << a << endl;
      	
      	//自定義輸出格式 [1,602214129,Hello Boost!]
      	boost::tuple b(1.0f,602214129,string("Hello Boost!"));
      	cout << boost::tuples::set_open('[') << boost::tuples::set_close(']')
      		<< boost::tuples::set_delimiter(',') << b << endl;
      //輸入
      	boost::tuple i;
      	cin >>i ;
      	cout << i < j;
      	cin >> boost::tuples::set_open('[') >> boost::tuples::set_close(']')
      		>> boost::tuples::set_delimiter(':');
      	cin >> j;
      	cout << j << endl;
      
      	return 0;
      }
      chunli@Linux:~/boost$ 
      
      chunli@Linux:~/boost$ g++ main.cpp  && ./a.out 
      (1 602214129 Hello Boost!)
      [1,602214129,Hello Boost!]
      (123 321 213)
      [123,321,213]
      [123:321]
      [123,321]
      chunli@Linux:~/boost$ g++ main.cpp  && ./a.out 
      (1 602214129 Hello Boost!)
      [1,602214129,Hello Boost!]
      234 567 890
      [0,0,0]
      [0,0]
      chunli@Linux:~/boost$

      Boost.array

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      using namespace std;
      
      int main()
      {
      	//boost::array arr1 = {9,1,8,2,7,3,6,4,0,5};//創(chuàng)建一個(gè)裝int類(lèi)型,容量是10個(gè)
      	boost::array arr1 = {{9,1,8,2,7,3,6,4,0,5}};//創(chuàng)建一個(gè)裝int類(lèi)型,容量是10個(gè)
      	sort(arr1.begin(),arr1.end());
      	copy(arr1.begin(),arr1.end(),ostream_iterator(cout," "));
      
      	return 0;
      }
      chunli@Linux:~/boost$ g++ main.cpp  -Wall && ./a.out 
      0 1 2 3 4 5 6 7 8 9 chunli@Linux:~/boost$

      Boost.unordered 數(shù)據(jù)插入

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      using namespace std;
      
      template
      void print(Iter first,Iter last)
      {
      	while(first != last)
      	{
      		cout << first->first << "," << first->second << endl;
      		first++;
      	}
      }
      
      int main()
      {
      	boost::unordered_map map1;
      	map1.insert(make_pair("Hello Boost",11));
      	map1.insert(make_pair("Hello World",12));
      	map1.insert(make_pair("Hello Linux",13));
      	map1.insert(make_pair("Hello C++",14));
      	map1["apple"] = 666;
      	map1["banana"] = 777;
      	map1["pare"] = 888;
      	
      	//map1["X2"],對(duì)map下標(biāo)操作,如果key不存在,就插入.盡量少用這種費(fèi)解的語(yǔ)法
      	cout << map1["對(duì)map下標(biāo)操作,如果key不存在,就插入"] << endl;//打印 0
      	print(map1.begin(),map1.end());
      
      	return 0;
      }
      chunli@Linux:~/boost$ g++ main.cpp  -Wall && ./a.out 
      0
      pare,888
      banana,777
      對(duì)map下標(biāo)操作,如果key不存在,就插入,0
      apple,666
      Hello C++,14
      Hello Linux,13
      Hello World,12
      Hello Boost,11
      chunli@Linux:~/boost$

      Boost,unordered hash_map桶的分布情況

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      using namespace std;
      
      template
      void print(Iter first,Iter last)
      {
      	while(first != last)
      	{
      		cout << first->first << "," << first->second << endl;
      		first++;
      	}
      }
      
      int main()
      {
      	boost::unordered_map map1;
      	map1.insert(make_pair("Hello Boost",11));
      	map1.insert(make_pair("Hello World",12));
      	map1.insert(make_pair("Hello Linux",13));
      	map1.insert(make_pair("Hello C++",14));
      	map1["apple"] = 666;
      	map1["banana"] = 777;
      	map1["pare"] = 888;
      	
      	//map1["X2"],對(duì)map下標(biāo)操作,如果key不存在,就插入.盡量少用這種費(fèi)解的語(yǔ)法
      	cout << map1["對(duì)map下標(biāo)操作,如果key不存在,就插入"] << endl;//打印 0
      	print(map1.begin(),map1.end());
      	/////////////////// 查看有多少個(gè)元素/////////////////////////////
      	cout << "map1 size:"<::local_iterator LIter;
      	for(LIter it = map1.begin(0);it != map1.end(0);++it)
      	{
      		cout << it->first << " " <second << endl;
      	}
      
      	return 0;
      }
      chunli@Linux:~/boost$ g++ main.cpp  -Wall && ./a.out 
      0
      pare,888
      banana,777
      對(duì)map下標(biāo)操作,如果key不存在,就插入,0
      apple,666
      Hello C++,14
      Hello Linux,13
      Hello World,12
      Hello Boost,11
      map1 size:8
      當(dāng)前共有16個(gè)桶
      每個(gè)桶的情況如下
      Bucket #0:2
      Bucket #1:0
      Bucket #2:0
      Bucket #3:0
      Bucket #4:0
      Bucket #5:0
      Bucket #6:1
      Bucket #7:1
      Bucket #8:1
      Bucket #9:2
      Bucket #10:0
      Bucket #11:1
      Bucket #12:0
      Bucket #13:0
      Bucket #14:0
      Bucket #15:0
      -------------------------------------------
      Hello Linux 13
      Hello World 12
      chunli@Linux:~/boost$

      Boost:Multi-Array 多維數(shù)組

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include "boost/multi_array.hpp"   
      #include "boost/cstdlib.hpp"   
      
      using namespace std;
      int main () {   
      	// Create a 3D array that is 3 x 4 x 2   
      	typedef boost::multi_array array;   
      	array A(boost::extents[3][4][2]);   
      
      	// Assign a value to an element in the array   
      	A[0][0][0] = 3.14;   
      
      	if(A[0][0][0] == 3.14)   
      	{
      		cout << "yes!" << endl;
      	}
      	else
      	{
      		cout << "no!" << endl;
      	}
      	return 0;
      }  
      
      chunli@Linux:~/boost$ g++ main.cpp  -Wall && ./a.out 
      yes!
      chunli@Linux:~/boost$

      Boost 多維數(shù)組,

      chunli@Linux:~/boost$ cat main.cpp 
      #include    
      #include "boost/multi_array.hpp"   
      #include "boost/array.hpp"   
      #include "boost/cstdlib.hpp"   
      using namespace std;
      int main () 
      {   
      	boost::array shape = {{ 5, 5, 5 }};//普通數(shù)組 ,裝3個(gè)數(shù)據(jù)  
      	boost::multi_array A(shape);  //設(shè)定3個(gè)維度的大小	 
      	/////////////填充////////////////////////
      	for(int i=0;i<5;i++)
      	{
      		for(int j=0;j<5;j++)
      		{
      			for(int k=0;k<5;k++)
      			{
      				A[i][j][k] = (i+j+k)*(i+j+k);
      			}
      		}
      
      	}
      	////////////遍歷/////////////////////////////
      	for(int i=0;i<5;i++)
      	{
      		for(int j=0;j<5;j++)
      		{
      			for(int k=0;k<5;k++)
      			{
      				printf("A[%d][%d][%d]=%3d,",i,j,k,A[i][j][k]);
      			}
      			printf("\n");
      		}
      		printf("\n");
      	}
      
      	return 0;
      }  
      chunli@Linux:~/boost$ g++ main.cpp  && ./a.out 
      A[0][0][0]=  0,A[0][0][1]=  1,A[0][0][2]=  4,A[0][0][3]=  9,A[0][0][4]= 16,
      A[0][1][0]=  1,A[0][1][1]=  4,A[0][1][2]=  9,A[0][1][3]= 16,A[0][1][4]= 25,
      A[0][2][0]=  4,A[0][2][1]=  9,A[0][2][2]= 16,A[0][2][3]= 25,A[0][2][4]= 36,
      A[0][3][0]=  9,A[0][3][1]= 16,A[0][3][2]= 25,A[0][3][3]= 36,A[0][3][4]= 49,
      A[0][4][0]= 16,A[0][4][1]= 25,A[0][4][2]= 36,A[0][4][3]= 49,A[0][4][4]= 64,
      
      A[1][0][0]=  1,A[1][0][1]=  4,A[1][0][2]=  9,A[1][0][3]= 16,A[1][0][4]= 25,
      A[1][1][0]=  4,A[1][1][1]=  9,A[1][1][2]= 16,A[1][1][3]= 25,A[1][1][4]= 36,
      A[1][2][0]=  9,A[1][2][1]= 16,A[1][2][2]= 25,A[1][2][3]= 36,A[1][2][4]= 49,
      A[1][3][0]= 16,A[1][3][1]= 25,A[1][3][2]= 36,A[1][3][3]= 49,A[1][3][4]= 64,
      A[1][4][0]= 25,A[1][4][1]= 36,A[1][4][2]= 49,A[1][4][3]= 64,A[1][4][4]= 81,
      
      A[2][0][0]=  4,A[2][0][1]=  9,A[2][0][2]= 16,A[2][0][3]= 25,A[2][0][4]= 36,
      A[2][1][0]=  9,A[2][1][1]= 16,A[2][1][2]= 25,A[2][1][3]= 36,A[2][1][4]= 49,
      A[2][2][0]= 16,A[2][2][1]= 25,A[2][2][2]= 36,A[2][2][3]= 49,A[2][2][4]= 64,
      A[2][3][0]= 25,A[2][3][1]= 36,A[2][3][2]= 49,A[2][3][3]= 64,A[2][3][4]= 81,
      A[2][4][0]= 36,A[2][4][1]= 49,A[2][4][2]= 64,A[2][4][3]= 81,A[2][4][4]=100,
      
      A[3][0][0]=  9,A[3][0][1]= 16,A[3][0][2]= 25,A[3][0][3]= 36,A[3][0][4]= 49,
      A[3][1][0]= 16,A[3][1][1]= 25,A[3][1][2]= 36,A[3][1][3]= 49,A[3][1][4]= 64,
      A[3][2][0]= 25,A[3][2][1]= 36,A[3][2][2]= 49,A[3][2][3]= 64,A[3][2][4]= 81,
      A[3][3][0]= 36,A[3][3][1]= 49,A[3][3][2]= 64,A[3][3][3]= 81,A[3][3][4]=100,
      A[3][4][0]= 49,A[3][4][1]= 64,A[3][4][2]= 81,A[3][4][3]=100,A[3][4][4]=121,
      
      A[4][0][0]= 16,A[4][0][1]= 25,A[4][0][2]= 36,A[4][0][3]= 49,A[4][0][4]= 64,
      A[4][1][0]= 25,A[4][1][1]= 36,A[4][1][2]= 49,A[4][1][3]= 64,A[4][1][4]= 81,
      A[4][2][0]= 36,A[4][2][1]= 49,A[4][2][2]= 64,A[4][2][3]= 81,A[4][2][4]=100,
      A[4][3][0]= 49,A[4][3][1]= 64,A[4][3][2]= 81,A[4][3][3]=100,A[4][3][4]=121,
      A[4][4][0]= 64,A[4][4][1]= 81,A[4][4][2]=100,A[4][4][3]=121,A[4][4][4]=144,
      
      chunli@Linux:~/boost$

      Boost.Property Map

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      #include 
      
      template 
      void foo(AddressMap address)
      {
      	std::cout << "foo: "<< sizeof(address) << std::endl;
      	typedef typename boost::property_traits::key_type 	key_type;
      	typedef typename boost::property_traits::value_type value_type;
      
      	value_type old_address, new_address;
      	key_type fred = "Fred";
      	old_address = get(address, fred);
      	new_address = "384 Fitzpatrick Street";
      	put(address, fred, new_address);
      
      	key_type joe = "工程師";
      	value_type& joes_address = address[joe];
      	joes_address = "西湖 中國(guó)浙江";
      }
      
      int main()
      {
      	std::map name2address;
      	boost::associative_property_map < std::map > address_map(name2address);
      	std::cout << "std::map :" << sizeof(name2address) << std::endl;
      
      	name2address.insert(make_pair(std::string("Fred"),std::string("710 West 13th Street")));
      	name2address.insert(make_pair(std::string("Joe"), std::string("710 West 13th Street")));
      	std::cout << "std::map :" << sizeof(name2address) << std::endl;
      
      	foo(address_map);
      	
      	for (std::map::iterator i = name2address.begin();i != name2address.end(); i++)
      	{
      		std::cout << i->first << ": " << i->second << std::endl;
      	}
      	return EXIT_SUCCESS;
      }
      chunli@Linux:~/boost$ g++ main.cpp -Wall  && ./a.out 
      std::map :48
      std::map :48
      foo: 8
      Fred: 384 Fitzpatrick Street
      Joe: 710 West 13th Street
      工程師: 西湖 中國(guó)浙江
      chunli@Linux:~/boost$

      Property Tree 解析XML文件

      chunli@Linux:~/boost$ cat debug_persons.xml 
       
        3
        
          
          23
          hugo
        
        
          23
           mayer
        
        
          30
          boy
        
        
      
      
      chunli@Linux:~/boost$ 
      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      
      struct person
      {
      	int age;
      	std::string name;
      };
      
      struct debug_persons
      {
      	int itsTotalNumber;
      	std::vector itsPersons;
      	void load(const std::string& filename);
      	void save(const std::string& filename);
      };
      
      std::ostream& operator<<(std::ostream& o,const debug_persons& dp)
      {
      	o << "totoal:" << dp.itsTotalNumber << "\n";
      	o << "persons\n";
      	BOOST_FOREACH(const person& p,dp.itsPersons)
      	{
      		o << "\tperson: Age:" << p.age << " Nmae:" << p.name << "\n";
      	}
      	return o;
      }
      
      void debug_persons::save( const std::string& filename )
      {
      	using boost::property_tree::ptree;
      	ptree pt;
      
      	pt.put("debug.total", itsTotalNumber);
      
      	BOOST_FOREACH(const person& p,itsPersons)
      	{
      		ptree child;
      		child.put("age",p.age);
      		child.put("name",p.name);
      		pt.add_child("debug.persons.person",child);
      	}
      	// Write property tree to XML file
      	write_xml(filename, pt);
      
      }
      
      void debug_persons::load( const std::string& filename )
      {
      	using boost::property_tree::ptree;
      	ptree pt;
      
      	read_xml(filename, pt);
      	itsTotalNumber = pt.get("debug.total");
      
      	BOOST_FOREACH(ptree::value_type &v, pt.get_child("debug.persons"))
      	{ 
      		//m_modules.insert(v.second.data());
      		person p;
      		p.age = v.second.get("age");
      		p.name = v.second.get("name");
      		itsPersons.push_back(p);
      	}
      }
      
      int main(int argc, char* argv[])
      {
      
      	try
      	{
      		debug_persons dp;
      		dp.load("debug_persons.xml");
      		std::cout<

      Property Tree 生成XML文件

      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      using namespace std;
      
      int main(int argc, char** argv) 
      {
      	vector vect_str;
      	vector::iterator it;
      
      	vect_str.push_back("111111");
      	vect_str.push_back("222222");
      	vect_str.push_back("333333");
      	vect_str.push_back("444444");
      
      	using namespace boost::property_tree;
      	ptree pt;   //定義一個(gè)樹(shù)pt
      	ptree out;
      	ptree cond;
      	ptree rule;
      	ptree data ;
      	ptree info ;
      
      	for (it = vect_str.begin(); it != vect_str.end(); it++)  //迭代vector
      	{
      		data.put(".key",it->data());
      		info.add_child("data",data);
      		data.clear() ;
      	}
      	pt.add_child("root.output.info",info);
      	info.clear();
      
      	BOOST_FOREACH(std::string& str, vect_str)  //迭代vector
      	{
      		for (int i = 0; i < 2; i++) 
      		{
      			cond.put(".desc", "123");
      			cond.put(".path", "345");
      			cond.put(".version", "567");
      			cond.put(".priority", "789");
      			rule.add_child("cond", cond);
      			cond.clear();
      		}
      		out.put(".where", str);
      		rule.add_child("out",out);
      		out.clear();
      		pt.add_child("root.output.rule", rule);
      		rule.clear();
      	}
      	//設(shè)置寫(xiě)入xml文件的格式,
      	boost::property_tree::xml_writer_settings settings =  boost::property_tree::xml_writer_make_settings (' ', 4);
      
      	//把property_tree 轉(zhuǎn)為XML文件
      	write_xml("newconfig.xml", pt, std::locale(), settings);
      	return 0;
      }
      chunli@Linux:~/boost$ g++ main.cpp  -Wall  && ./a.out 
      chunli@Linux:~/boost$ cat newconfig.xml 
      
      
          
              
                  
                  
                  
                  
              
              
                  
                  
                  
              
              
                  
                  
                  
              
              
                  
                  
                  
              
              
                  
                  
                  
              
          
      
      chunli@Linux:~/boost$

      Property Tree 解析JSON文件

      chunli@Linux:~/boost$ cat test.json 
      {
          "rate":{
              "linktype":[0.8, 1.0, 1.0, 0.7, 0.4, 0.7, 0.8, 0.8, 0.9, 0.9, 0.4, 0.8, 1.0],
              "width":[[0.6, 0.8],
                       [0.7, 0.87],
                       [1.0, 1.2],
                       [1.2, 1.4],
                       [1.0, 1.0]],
              "use_toll":[0.33, 1.2]
          },
          "turn_cost":{
              "uturn":{
                  "Hturn":0,
                  "triangle":1200,
                  "normal":[1200, 300, 60, 5]
              }
          }
      }
      chunli@Linux:~/boost$ cat main.cpp 
      #include 
      #include 
      #include 
      #include 
      
      using namespace std;
      
      int main()
      {
      	boost::property_tree::ptree pt;
      	boost::property_tree::json_parser::read_json("test.json", pt);
      
      	boost::property_tree::ptree child_linktype = pt.get_child("rate.linktype");
      
      	BOOST_FOREACH(boost::property_tree::ptree::value_type &vt, child_linktype) 
      	{
      		cout << vt.second.get_value() << "  ";
      	}
      	cout << endl;
      
      	return 0;
      }
      chunli@Linux:~/boost$ g++ main.cpp -Wall  && ./a.out 
      0.8  1  1  0.7  0.4  0.7  0.8  0.8  0.9  0.9  0.4  0.8  1  
      chunli@Linux:~/boost$

      Property Tree 生成JSON文件

      chunli@Linux:~/boost$ cat main.cpp 
      #include   
      #include   
      #include   
      #include   
      #include   
      using namespace std;  
      using namespace boost::property_tree;  
      
      int main(){   
      	ptree pt_1,pt_11,pt_12;  
      
      	pt_11.put("id","3445");  
      	pt_11.put("age",29);  
      	pt_11.put("name","chen");      
      
      	pt_12.push_back(make_pair("",pt_11));  
      	pt_12.push_back(make_pair("",pt_11));  
      	//replace or create child node "data"  
      	pt_1.put_child("data",pt_12);      
      	ostringstream os;  
      	write_json(os,pt_1);  
      	cout<

      另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。


      當(dāng)前標(biāo)題:2C++Boost容器-創(chuàng)新互聯(lián)
      分享URL:http://www.ef60e0e.cn/article/dodoee.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        黄陵县| 昭通市| 宁阳县| 高阳县| 达尔| 广南县| 钟祥市| 宕昌县| 江津市| 宁南县| 台南县| 称多县| 阳东县| 南阳市| 临高县| 乌鲁木齐市| 都江堰市| 海南省| 库伦旗| 陇西县| 调兵山市| 古交市| 永清县| 东乌珠穆沁旗| 元朗区| 哈密市| 讷河市| 扎兰屯市| 霍林郭勒市| 上虞市| 易门县| 青阳县| 铜山县| 雷山县| 乐山市| 河曲县| 驻马店市| 鲜城| 托里县| 葵青区| 淮南市|