
C++ primer笔记与习题
文章平均质量分 61
小野
now student
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【每日一练】(第2期)关于静态成员的理解
//思考题一:// testStatic.cpp : 请问下面的代码有没有错误?怎么理解?//#include using namespace std;class A{public: int i; static A a;};A A::a;int main(){ A::a.a.a.a.a原创 2012-12-25 09:59:15 · 546 阅读 · 0 评论 -
使用默认构造函数一个易犯的错误
初级 C++ 程序员常犯的一个错误是,采用以下方式声明一个用默认构造函数初始化的对象: // oops! declares a function, not an object Sales_item myobj();The declaration of myobj compiles without complaint. However, when we t原创 2013-01-17 17:13:37 · 682 阅读 · 0 评论 -
习题9.43
Exercise 9.43:Use a stack to process parenthesized expressions. When you see an open parenthesis, note that it was seen. When you see a close parenthesis after an open parenthesis,pop elements d原创 2012-12-22 16:09:38 · 509 阅读 · 0 评论 -
如何学好C++语言
C++是最难的语言。这个世界上最难的编程语言可能非C++莫属了。你千万不要以为几天就可以学好C++,C++的学习曲线是相当BT的,你可以看看这篇文章。C++是一门很自由的语言,自由到了有点BT和恐怖的地步。我甚至认为C++并不是一门成熟的编程语言,因为太容易犯错了。所以,你一定要在一开始就要有很小心谨慎的态度,并把C++当成一种难以训服的猛兽来看待。多问“为什么要这样”的问题。学习转载 2013-01-04 09:15:55 · 726 阅读 · 0 评论 -
习题9.32
Exercise 9.32:Explain what the following program does:解释下面程序实现的功能: vector svec; svec.reserve(1024); string text_word; while (cin >> text_word) svec.push_bac原创 2012-12-18 15:12:43 · 684 阅读 · 0 评论 -
习题9.27
Exercise 9.27:Write a program to process a list of strings. Look for a particular value and, if found, remove it. Repeat the program using adeque.编写程序处理一个 string 类型的 list 容器。在该容器中寻找一个特殊值,如果找到,原创 2012-12-14 21:53:12 · 673 阅读 · 0 评论 -
习题9.20
Exercise 9.20:Write a program to compare whether a vector contains the same elements as alist.编写程序判断一个 vector 容器所包含的元素是否与一个 list 容器的完全相同。#include#include#includeusing namespace原创 2012-12-14 11:04:01 · 509 阅读 · 0 评论 -
习题9.18
Exercise 9.18:Write a program to copy elements from a list of ints into twodeques. Thelist elements that are even should go into onedeque and those that are odd into the second.编写程序将 int 型的 li原创 2012-12-13 20:02:28 · 510 阅读 · 0 评论 -
习题9.39输出最长和最短单词
Exercise 9.39:Write a program that, given the strings已知有如下 string 对象: string line1 = "We were her pride of 10 she named us:"; string line2 = "Benjamin, Phoenix, the Prodigal" s原创 2012-12-26 09:44:21 · 1826 阅读 · 0 评论 -
习题9.38
Exercise 9.38:Write a program that, given the string已知有如下 string 对象: "ab2c3d7R4E6"finds each numeric character and then each alphabetic character. Write two versions of the program.原创 2012-12-25 20:00:49 · 599 阅读 · 0 评论 -
【每日一练】(第4期)C++编程规范-继承
class Base{public: virtual void display(const std::string& strShow = "I am Base class !") { std::cout << strShow << std::endl; } virtual ~Base(){}};class Derive: p原创 2012-12-25 10:03:36 · 722 阅读 · 0 评论 -
【每日一练】(第3期)关于STL的泛型算法count_if()
//思考题二:理解下面的代码,说说这段代码的优点和缺点。#include #include #include #include using namespace std;class TestClass{public: TestClass(size_t val = 0) : bound(val) { } boo原创 2012-12-25 10:01:53 · 680 阅读 · 0 评论 -
【每日一练】(第1期)关于调用规范和函数指针
// testFunc.cpp : 关于调用规范和函数指针#include using namespace std; class Demo{ int x, y; public: Demo(int x, int y) : x(x), y(y) { } virtual void __stdc原创 2012-12-25 09:21:49 · 818 阅读 · 1 评论 -
简单的string类实现
自己实现的一个简单的string类,原来以为挺简单的,真正写起来才发现,还是有很多细枝末节的东西没有考虑清楚哦;比如:1.insert的在pos处插入是表示 "插入在索引为pos的元素之前"比如对于s1="abcd", s1.insert(2, f), s1变成了"abfcd"2.remove(char c)这个接口表示删除simple_string中所有的c. 比如s1="a原创 2013-03-11 16:04:38 · 958 阅读 · 0 评论