2012年10月26日

vector tip

摘要: 【1】vector 不是一种数据类型,而只是一个类模版,可用来定义任意多种数据类型。vector 类型的每一种都指定了其保存元素的类型。因此,vector<int>与vector<string>都是数据类型。【2】vector 对象(以及其他标准库容器对象)的重要属性就在于可用在运行时高效地添加元素。因为vector 增长的效率高,在元素之已知的情况下,最好是动态地添加元素。虽然可以对给定的元素个数的 vector 对象预先分配内存,但是更有效的方法是先初始化一个空Vector对象,然后再动态地增加元素。【3】vector 对象的 size 操作返回相应 vector 阅读全文

posted @ 2012-10-26 21:21 零风腾飞 阅读(149) 评论(0) 推荐(0)

C++ primer ex 3.8

摘要: #include <string> #include <iostream> using namespace std; void connstring() { cout<<"请输入字符串(#结束):"<<endl; string resultStr,userInputStr; while(cin>>userInputStr) { if (!userInputStr.compare("#")) { break; } resultStr+=userInputStr; } cout<<&qu 阅读全文

posted @ 2012-10-26 21:12 零风腾飞 阅读(165) 评论(0) 推荐(0)

C++ primer 第3章 ex3.10

摘要: #pragma once #include <string> #include <iostream> #include <cctype> using namespace std; void getstring() { string result_str,userInput_str; bool hasPunct=false; cout<<"请输入字符传:"<<endl; cin>>userInput_str; for(string::size_type i=0;i<userInput_str.siz 阅读全文

posted @ 2012-10-26 20:57 零风腾飞 阅读(137) 评论(0) 推荐(0)

导航