![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
文章平均质量分 80
ibaicai2
这个作者很懒,什么都没留下…
展开
-
求数组长度
c++中,求一个数组的大小,一般用sizeof(p)/sizeof(p[0]) 就可以了。但因为数组作为非引用参数传递的时候,会退化为指针,所以这样直接用sizeof来计算数组大小,可能会存在潜在的错误。 #include #include using namespac转载 2011-09-26 13:23:07 · 604 阅读 · 0 评论 -
C++ Primer 9.40习题 计算sentence有多少个单词,并输出最长、最短的单词d
代码思路: 1、单词数 = 空格数 + 1 2、采用迭代器遍历sentence,用两个迭代器b,e来锁定一个单词,并用一个string对象tmp记录该单词 3、由于最长、最短的单词可能不止一个,所以用vector存储最长、最短单词,当发现一个最长的单词时,先调用clear清空该容器,然后再用assign把单词存入maxlegth,遇到长度相同的时采用push_back()操作,将单词压入容器原创 2012-12-09 22:42:56 · 839 阅读 · 0 评论 -
C++中基类与派生类的复制控制
本博文的创作思路源自《C++ Primer(4th Ed )》的习题15.20 运行环境Ubuntu 、g++ #include #include using namespace std; class Item_base { public: Item_base(const string &book = "Item_base", double SalesPrice = 1): i原创 2013-01-09 21:09:55 · 701 阅读 · 0 评论