当前位置:  编程技术>c/c++/嵌入式
本页文章导读:
    ▪STL之vector容器详解      vector 容器vector是C++标准模版库(STL,Standard Template Library)中的部分内容。之所以认为是一个容器,是因为它能够像容器一样存放各种类型的对象,简单的说:vector是一个能够存放任意类型的动态.........
    ▪如何成为一个专业级的c++ 程序员--- A answer from quora      C++ is a Huuuuuge Language.The Path towards Expertise would be:Understanding C++ - Step 0You have got to read The C++ Programming Language by Stroustrup, no way you can escape this. http://www.amazon.com/The-Progra...   &n.........
    ▪Cocoa中检查文件目录是否有权限的方法      cocoa中虽然有[[NSFileManager defaultManager] fileExistsAtPath:filename]来检查文件是否可写的方法,但是对文件目录却不起作用,没办法只好自己写一个比较山寨的方法:bool IsDirectoryWritable(NSString *dir){ .........

[1]STL之vector容器详解
    来源:    发布时间: 2013-10-14

vector 容器

vector是C++标准模版库(STL,Standard Template Library)中的部分内容。之所以认为是一个容器,是因为它能够像容器一样存放各种类型的对象,简单的说:vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。

使用vector容器之前必须加上<vector>头文件:#include<vector>;

vector属于std命名域的内容,因此需要通过命名限定:using std::vector;也可以直接使用全局的命名空间方式:using namespace std;

 

vector成员函数

c.push_back(elem)在尾部插入一个elem数据。

vector<int> v;
v.push_back(1);

c.pop_back()删除末尾的数据。

vector<int> v;
v.pop_back();

c.assign(beg,end)将[beg,end)一个左闭右开区间的数据赋值给c。

vector<int> v1,v2;
v1.push_back(10);
v1.push_back(20);
v2.push_back(30);
v2.assign(v1.begin(),v1.end());

c.assign (n,elem)将n个elem的拷贝赋值给c。

vector<int> v;

v.assign(5,10);//往v里放5个10

c.at(int index)传回索引为index的数据,如果index越界,抛出out_of_range异常。

vecto<int> v;
cout << v.at(2) << endl;//打印vector中下标是2的数据

c.begin()返回指向第一个数据的迭代器。

c.end()返回指向最后一个数据之后的迭代器。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::iterator it;
for(it = v.begin();it!=v.end();it++){
cout << *it << "\t";
}
cout << endl;

c.rbegin()返回逆向队列的第一个数据,即c容器的最后一个数据。

c.rend()返回逆向队列的最后一个数据的下一个位置,即c容器的第一个数据再往前的一个位置。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
vector<int>::reverse_iterator it;
for(it = v.rbegin();it!=v.rend();it++){
cout << *it << "\t";
}
cout << endl;

c.capacity()返回容器中数据个数,翻倍增长。

vector<int> v;
v.push_back(1);
cout << v.capacity() << endl; // 1
v.push_back(2);
cout << v.capacity() << endl; // 2
v.push_back(3);
cout << v.capacity() << endl; // 4

c.clear()移除容器中的所有数据。

vector<int>::iterator it;
for(it = v.begin();it!=v.end();it++){
cout << *it << "\t";
}
v.clear();
for(it = v.begin();it!=v.end();it++){
cout << *it << "\t";
}
cout << endl;

c.empty()判断容器是否为空。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!v.empty()){
cout << "v is not empty!" << endl;
}

c.erase(pos)删除pos位置的数据,传回下一个数据的位置。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin());

c.erase(beg,end)删除[beg,end)区间的数据,传回下一个数据的位置。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.erase(v.begin(),v.end());

c.front()返回第一个数据。

c.back()传回最后一个数据,不检查这个数据是否存在。

vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
if(!vec.empty()){
cout << “the first number is:” << v.front() << endl;
cout << “thelast number is:” << v.back() << endl;
}

c.insert(pos,elem) 在pos位置插入一个elem的拷贝,返回插入的值的

    
[2]如何成为一个专业级的c++ 程序员--- A answer from quora
    来源:    发布时间: 2013-10-14

C++ is a Huuuuuge Language.

The Path towards Expertise would be:

  • Understanding C++ - Step 0

You have got to read The C++ Programming Language by Stroustrup, no way you can escape this. http://www.amazon.com/The-Progra...
    

  • Understanding Histrory of C++ and Why come they designed the C++ Features - Step 1

The Design and Evolution of C++ Book from Stroustrup would help you.http://www.amazon.com/The-Design...

  • Understanding Internals whats happening when you declare classes. -Step 2

Inside C++ Object Model by Stanley Lippman would help you.http://www.amazon.com/Inside-Obj...

  • How to write Efficient Programs in C++ - Step 3

Agner Fog Optimization Manuals would give you Start. http://www.agner.org/optimize/ 

  • How to write Correct C++ Programs - Step 4

Effective and More Effective C++ book would help, you cannot clear any C++ technical Interview without reading this. Better search for Scott Meyers in Google and Read Everything. He has huge insights for writing correct way of C++

  • http://www.amazon.com/Effective-...
  • http://www.amazon.com/More-Effec...
  •         

    • Understanding Design Patterns - Step 5

    It would give basics to understand Huge C++ framework libraries such as Qt , Boost etc., The Gang of 4 Book would help you. http://www.amazon.com/Design-Pat...

    • Understanding How to Create Efficient Frameworks - Step 6

    API Design by Martin Reddy would give you a start. http://www.amazon.com/API-Design...


    Phew .... We came so far without even touching Meta Programming and Templates.


    • Meta Programming and Templates - Step 7



  • Understanding C++ Templates would help. http://www.amazon.com/C-Template...
  • Modern C++ Techniques from  Andrei Alexandrescu  would give you a start.http://www.amazon.com/Modern-Des...
  • Another good stuff from Andrei Alexandrescu http://www.amazon.com/Elements-P...
  • Knowing how to use STL also helps, The C++ Standard Library.http://www.amazon.com/The-Standa...
  •  

    • Understanding How to become proficient in MetaProgramming - Step 8

    For this you need to take different path instead of learning C++ , you would learn Haskell or CommonLisp. Haskell would be perfect. http://bartoszmilewski.com/2009/...
    But i took the other one (Common Lisp). http://letoverlambda.com/

    • Now its time to lose focus on C++  and Learn Compilers, Functional programming, meta programming etc..
    • Implement C++ Compiler. (no mere souls  done that if you can pull off you got big future in Google,Facebook etc..)


    You may notice from Step 8, it become vague path. So I would say after Step 8 you need to invent your own Path. 

    Did I mention to read C++ 0x11 oh god So much to read but life is too short .

    So my opinion would be C++ language is gonna stay for foreseeable future unless we work on computer which is not based on Von neumann architecture.
    So better invest your 10 years to expertise C++  and Computer programming.

    It does pay off, you can demand Good Salary, no matter what hype is (VB, Java, C# and now Go). Its tested against Time .

    本文链接


        
    [3]Cocoa中检查文件目录是否有权限的方法
        来源:    发布时间: 2013-10-14

    cocoa中虽然有[[NSFileManager defaultManager] fileExistsAtPath:filename]来检查文件是否可写的方法,但是对文件目录却不起作用,没办法只好自己写一个比较山寨的方法:

    bool IsDirectoryWritable(NSString *dir)
    {
        bool result = false;
        
        if(![[NSFileManager defaultManager] fileExistsAtPath:dir])
            return result;
        
        NSString* fileName = [dir stringByAppendingFormat:@"/  _#t.txt"];
        NSData *data = [fileName dataUsingEncoding:NSUTF8StringEncoding];
        [data writeToFile:fileName atomically:NO];
        
        result = [[NSFileManager defaultManager] fileExistsAtPath:fileName];
        if(result)
        {
            [[NSFileManager defaultManager] removeItemAtPath:fileName error:NULL];
        }
        
        return true;
    }

    这个方法的不好之处就是有可能用于尝试的fileName可能已经存在(虽然已经起的很奇怪了),这样会导致返回结果不准确,也有可能测试文件创建成功了但是删除却失败了,那么也会导致下次测试不准确,。如果哪位高人有更好的办法,麻烦指教。



    RTY 2013-01-07 23:24 发表评论

        
    最新技术文章:
    ▪C++单例模式应用实例
    ▪C++设计模式之迭代器模式
    ▪C++实现动态分配const对象实例
    ▪C++设计模式之中介者模式
    ▪C++设计模式之备忘录模式
    ▪C++插入排序算法实例
    ▪C++冒泡排序算法实例
    ▪C++选择排序算法实例
    ▪C++归并排序算法实例
    ▪C++设计模式之观察者模式
    ▪C++中复制构造函数和重载赋值操作符总结
    ▪C++中关键字Struct和Class的区别 iis7站长之家
    ▪C++设计模式之策略模式
    ▪C++设计模式之访问者模式
    ▪C++设计模式之模板方法模式
    ▪C++实现下载的代码
    ▪C++模板之特化与偏特化详解
    ▪C++实现查壳程序代码实例
    ▪C语言、C++内存对齐问题详解
    ▪C语言、C++中的union用法总结
    ▪C++基于CreateToolhelp32Snapshot获取系统进程实例
    ▪C++中memcpy和memmove的区别总结
    ▪C++通过TerminateProess结束进程实例
    ▪C++内存查找实例
    ▪C++实现CreatThread函数主线程与工作线程交互的...
    ▪C++设计模式之桥接模式
    ▪C++中关键字Struct和Class的区别
    ▪C++设计模式之组合模式
    ▪C++ COM编程之什么是组件?
    ▪C++ COM编程之什么是接口?
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3