2012年3月1日

C++ Primer 第11章 习题11.9

摘要: //泛型算法中对容器元素从新排序的算法 //11.9.cpp //读入文本文件 //统计长度不小于4的单词,并输出输入序列中不重复的单词 #include<iostream> #include<fstream> #include<vector> #include<algorithm> #include<string> using namespace std; //用于将单词按长度排序的比较函数 bool isShorter(const string &s1,const string &s2) { return s1.s 阅读全文

posted @ 2012-03-01 18:33 1.曲待续 阅读(116) 评论(0) 推荐(0) 编辑

C++ Primer 第11章 习题11.6

摘要: //11.6.cpp //使用fill_n编写程序 //将一个int型序列的值设为0 #include<iostream> #include<vector> #include<iterator> using namespace std; int main() { vector<int> ivec; ivec.resize(10); //使该vector容器包含10个元素 fill_n(ivec.begin(),ivec.size(),0); //输出vector对象中的元素 for(vector<int>::iterator iter 阅读全文

posted @ 2012-03-01 17:08 1.曲待续 阅读(92) 评论(0) 推荐(0) 编辑

C++ Primer 第11章 习题11.3

摘要: //11.3.cpp //用accumulate统计vector<int>容器对象中的元素之和 #include<iostream> #include<vector> #include<numeric> using namespace std; int main() { vector<int> ivec; int ival; int sum; //读入int型元素带vector对象中 cout<<"Enter some integers(Ctrl+z to end):"<<endl; whi 阅读全文

posted @ 2012-03-01 17:07 1.曲待续 阅读(104) 评论(0) 推荐(0) 编辑

C++ Primer 第11章 习题11.1

摘要: //11.1.cpp //algorithm头文件定义一个名为count的函数 //其功能类似于find。 //这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果。 //编写程序读取一系列int型数据,并将它们存储到vector对象中 //统计某个值出现了多少次 #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<int> ivec; int ival; int ival1; int cnt 阅读全文

posted @ 2012-03-01 17:05 1.曲待续 阅读(115) 评论(0) 推荐(0) 编辑

导航