随笔分类 -  C++学习--C++标准程序库

摘要:今天看书,看到这个例子感觉不错。抄下来,兴许以后能用上。先给个例子吧:随意的一个字符串,比如pots * pans,本程序会输出stop * snap下面给出代码,大家可以根据自己的需要来更改。 1 // StandLibP476.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <string> 7 8 using namespace std; 9 10 int _tmain(int argc, _TCHAR* argv[])11 { 阅读全文
posted @ 2012-04-04 19:16 ziyoudefeng 阅读(1207) 评论(1) 推荐(0)
摘要:由于是疑问贴,所以直接上代码:<代码中红色部分有疑问> 1 // StandLibP307.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <string> 7 #include <vector> 8 #include <functional> 9 #include <algorithm>10 using namespace std;11 12 13 class Person {14 1 阅读全文
posted @ 2012-04-02 16:43 ziyoudefeng 阅读(908) 评论(0) 推荐(0)
摘要:今天看C++ 标准程序库里面讲到说map[key] = value;这种方式效率低,原因是新元素必须先使用default构造函数将实值(value)初始化,而这个初值马上又被真正的value给覆盖了。然后就想自己测试一下,下面是自己的测试代码,然后后面有自己对运行结果的不解。1、定义一个value型别,供map中使用 1 #pragma once 2 #include <iostream> 3 4 class TestMapSec 5 { 6 public: 7 TestMapSec(void) { std::cout << "default construc 阅读全文
posted @ 2012-04-01 17:45 ziyoudefeng 阅读(2365) 评论(4) 推荐(1)
摘要:先给一个小程序,大家猜一下结果是什么: 1 // StandLibP112.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <vector> 6 #include <algorithm> 7 #include <iostream> 8 9 using namespace std;10 11 int _tmain(int argc, _TCHAR* argv[])12 {13 14 vector<int> vec;15 16 for ( int i = 0 阅读全文
posted @ 2012-03-28 20:00 ziyoudefeng 阅读(2073) 评论(0) 推荐(1)