C++标准扩展应用技巧分享

开发 后端
我们今天在这篇文章中主要为大家介绍了C++标准扩展的一些基本应用。对C++编程语言有兴趣的朋友们可以从中加深对这一语言的认知程度。

对于经验丰富的编程人员来说,C++编程语言他们应该再熟悉不过了。这样一款功能强大的语言,给他们的程序开发带来了非常大的好处,我们今天就可以从C++标准扩展的方法来体验一下这语言的功能特点。

今天实验一下C++标准扩展中的shared_ptr的使用,结果在gcc4.1上怎么也编译不过去,上网查了一下,还下载了TR1的手册。终于明白了,要在#include中加入

#include < tr1/memory> 
#include < iostream> 
#include < string> 
#include < tr1/array> 
#include < tr1/memory> 
using namespace std;  
using std::tr1::shared_ptr;  
 
class Widget  
{  
public:  
Widget()   
{  
pstr = new string("Hello world!");  
cout < <  "Widget's construction is called" < <  endl;   
}  
Widget(const Widget& rhs) { cout < <  "Widget's copy 
construction is called" 
< <  endl; }   Widget& operator=(const Widget& rhs) { return *this; }   ~Widget()    {   delete pstr;   cout < <  "Destruction is called" < <  endl;    }   private:   string* pstr;   };   int main()   {   auto_ptr< Widget> pInv(new Widget);   auto_ptr< Widget> pInv2(pInv);   shared_ptr< Widget> pInvN(new Widget);   array< int, 5> a = {{1,2,3,4,5}};   cout < <  a[3] < <  endl;   return 0;  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.

这个文件。呵呵,可能是自己太不小心了!这次C++标准扩展的部分,根据TR1的说明主要有:

Reference Wrappers   
Shared_ptr   
result_of   
mem_fn   
Function Object Binders   
Polymorphic Function Wrappers   
Type Traits   
Random Numbers   
Tuples   
Array   
Hash Functions   
Regular Expressions   
Complex Number Algorithms 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

这些C++标准扩展部分,我们看到了期待以久的正则表达式也在这里面哦!

【编辑推荐】

  1. C++单件模式实现代码详解
  2. C++获取文件具体方法详解
  3. C++ makefile写法标准格式简介
  4. C++统计对象个数方法详解
  5. C++ #define预处理指令特点评比
责任编辑:曹凯 来源: 博客园
相关推荐

2010-02-01 11:13:00

C++ Traits

2010-02-04 14:58:06

C++内存分配

2010-02-01 17:09:07

C++链表操作

2010-02-05 13:44:06

C++ eof()函数

2010-02-06 14:28:38

C++标准输入输出

2010-02-06 16:16:01

C++冒泡排序

2010-02-05 18:04:21

C++剪切板

2011-07-13 16:36:11

C++

2010-02-03 15:35:00

C++输入输出汉字

2010-02-05 17:25:26

C++标识符命名规则

2010-02-26 10:46:12

WCF行为扩展

2010-02-06 13:52:39

C++ profile

2010-02-06 10:24:48

C++二维数组初始化

2010-02-06 17:09:29

C++文件拷贝

2010-02-02 10:46:51

C++获取文件大小

2010-02-04 11:38:43

C++获取当前路径

2009-12-08 13:18:17

2010-02-03 16:04:34

C++标准类库

2010-02-04 15:19:38

C++获取CPU信息

2010-02-05 14:59:31

C++命令行模式编译设
点赞
收藏

51CTO技术栈公众号