C++
a_xianzZ
这个作者很懒,什么都没留下…
展开
-
“行参为引用”的思考
1.一个简单程序判断知否含有大写字母#include using std::cout; using std::cin; using std::endl;#include using std::string; #include #include using std::vector;#include using std::begin; using std::end;#in原创 2016-01-15 16:38:38 · 339 阅读 · 0 评论 -
iostream迭代器操作"txt文本文件"无法写入的思考
题:从“in.txt”读取数据,然后分奇偶分别存到“out_odd.txt”和“out_even.txt”中#include #include #include #include #include #include #include using std::cout; using std::endl;using std::vector;using std::string;in原创 2016-09-03 22:58:42 · 525 阅读 · 0 评论 -
"accumulate"的思考
int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); vector ivec{1,2,3,4,5.1}; double sum = accumulate(ivec.begin(),ivec.end(),0); cout << "sum: " << sum << endl; ret原创 2016-08-10 21:56:21 · 277 阅读 · 0 评论 -
顺序容器“inset”的思考
int main(int argc,char *argv[]){ QCoreApplication a(argc, argv); list ilist{1,2,3,4,}; list::iterator lst = ilist.begin(); lst = ilist.insert(lst,0); cout << "ouput:" << *lst << e原创 2016-08-07 11:57:10 · 299 阅读 · 0 评论 -
"lambda"和“bind”的初步思考
先来看个问题:在一个string的vector容器中,寻找第一个长度大于4的元素。inline bool check_size(const string& s){ return s.size() > 4;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); vector v{"1", "原创 2016-08-17 11:42:27 · 331 阅读 · 0 评论 -
C++ 可变参数的函数
#include #include int sum(std::initializer_list il){ int sum = 0; for (auto i : il) sum += i; return sum;}int main(void){ std::cout << sum({1, 2, 3, 4, 5}) << std::endl; re转载 2016-07-22 10:37:35 · 278 阅读 · 0 评论 -
"partition"和“stable_partition”的思考
"partition"和“stable_partition”设计的目的是根据一个谓词而把容器分为两部分。可是他们具体的区别在哪里呢?下面我们来验证一下。void elimDups(vector &words){ sort(words.begin(), words.end()); auto it = unique(words.begin(),words.end());原创 2016-08-15 22:01:38 · 824 阅读 · 0 评论 -
C++重载函数 const形参 引用指针 const_cast
一般来说,对于重载函数来说,由于顶层const不影响传入函数的对象,所有两个函数只是顶层const的区别的话,两个函数是等价的,定义为重载函数是非法的。 但是,另一方面,对于指针和引用来说,可以通过区分形参指向的是常量还是非常量来实现函数重载。此时的const是底层的。Example:Record lookup(Account&); //函数作用于Account的引用R原创 2016-07-23 07:49:37 · 1540 阅读 · 0 评论 -
32位电脑“内置类型"所占空间大小
#include using std::cout; using std::cin; using std::endl;#include using std::string; #include #include using std::vector;#include using std::begin; using std::end;#include using std::si原创 2016-01-13 16:26:19 · 586 阅读 · 0 评论 -
“寻找奇数”的思考
题:使用条件运算符从vector中寻找哪些元素的值是奇数,然后将这些奇数的值翻倍。#include using std::cout; using std::cin; using std::endl;#include using std::string; #include #include using std::vector;#include using std::begi原创 2016-01-13 15:40:38 · 389 阅读 · 0 评论 -
C++11:"auto"和"decltype"类型说明符的思考
//例1//编译器:gcc 4.8.1 系统:windows#include int main(){ int i = 1; auto a = i; decltype(i) d = 2; std::cout << "a: " << a << std::endl; std::cout << "d: " << d << std::endl; return 0; }输出原创 2016-01-07 09:52:18 · 491 阅读 · 0 评论 -
“顶层const”和“底层const”的思考
“顶层const"顾名思义就是对对象本身的一种限制,而使得对象本身为常量。例:const int a = 1; //对对象本身做了限制,变为常量,是“顶层const”同理,”底层const"通常与指针和引用等复合类型的基本类型有关,那是对指针、引用类型所牵连的对象的限制,那是对底层的限制。例:const int a = 1;const int *p = &a; //对存储的a原创 2016-01-06 21:39:36 · 398 阅读 · 0 评论 -
C++中while(std::cin >> value)的思考
例子:#include int main(){ int sum = 0, value = 0; while(std::cin >> value) { sum += value; } std::cout << "sum is " << sum << std::endl; return 0;}输入运算符( >> )原创 2016-01-06 06:35:49 · 3368 阅读 · 0 评论