![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++/stl
文章平均质量分 68
天地蜉蝣
.
展开
-
STL容器删除元素的陷阱(转)
今天看Scott Meyers大师的stl的用法,看到了我前段时间犯的一个错误,发现我写的代码和他提到错误代码几乎一模一样,有关stl容器删除元素的问题,错误的代码如下:std::vector mFriendList;...std::vector::iterator iter =转载 2011-07-11 17:34:50 · 712 阅读 · 0 评论 -
深入研究 C++中的 STL Deque 容器
传送门: http://www.yesky.com/100/1889600.shtml转载 2012-04-28 12:27:43 · 560 阅读 · 0 评论 -
C++ 内存池 -- C++ Memory Pool
http://www.rosoo.net/a/201010/10268.htmlhttp://www.codeproject.com/cpp/MemoryPool.asp转载 2012-05-31 12:20:18 · 504 阅读 · 0 评论 -
wsting <---> string
#include std::string ws2s(const std::wstring& ws){ std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Source = ws.c_str转载 2012-05-17 11:48:23 · 1507 阅读 · 0 评论 -
读未知大小文件
#include #include using namespace std; ifstream ifile( "test.dat ", ios::binary); ifile.seekg(0, ios::end); int filelen = ifile.tellg(); char *pbuf = new char[file转载 2012-07-19 15:18:25 · 776 阅读 · 0 评论 -
C/C++语法知识:typedef struct 用法详解
第一篇:typedef struct与struct的区别1. 基本解释typedef为C语言的关键字,作用是为一种数据类型定义一个新名字。这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等)。在编程中使用typedef目的一般有两个,一个是给变量一个易记且意义明确的新名字,另一个是简化一些比较复杂的类型声明。至于typedef有什转载 2013-01-15 13:49:22 · 530 阅读 · 0 评论 -
程序崩溃,但暂停的位置不在错误发生的行的解决方法
如果经常遇到程序Crash但暂停的位置不在错误发生的行,可以检查一下VC的Exceptions设置: Debug>Exceptions 在设置界面中把C++ Exceptions和Win32 Exceptions都选中,这样出现错误(例如数组越界,坏指针)立刻在错误的地方中断。而不是在控制台输出一个First Chance exceptions地址,却中断到不正确的代码行。转载 2013-02-22 09:03:59 · 677 阅读 · 0 评论 -
C++标准里 string和wstring
在C++标准里定义了两个字符串string和wstring typedef basic_string string; typedef basic_string wstring; 前者string是常用类型,可以看作char[],其实这正是与string定义中的_Elem=char相一致。而wstring,使用的是wchar_t类型,这是宽字符,用于满足非转载 2014-11-06 11:13:23 · 52336 阅读 · 1 评论 -
pthread_jion
#include #include #include #include #include #pragma warning (disable:4716)void * pthread_func_test(void * arg);int main(){ pthread_t thread1,thread2; pthread_create(&thread1,NULL,pthr转载 2014-11-06 18:29:21 · 678 阅读 · 0 评论 -
boost 最短路径 johnson
#include #include #include #include #include #include #include #include #include intmain(){ using namespace boost; typedef adjacency_list<vecS, vecS, undirectedS, no_property,转载 2015-04-29 10:27:06 · 787 阅读 · 0 评论 -
const 指针 和 typedef 混合测试
#include #include #include using namespace std;void main(){ int nNum1 = 111; int nNum2 = 222; int* pNum = &nNum2; // effective c++中这么说: // *号在const左边为const data; (只读指针) // *号在原创 2011-11-27 18:49:02 · 513 阅读 · 0 评论 -
STL容器的适用情况(转)
原文:http://hsw625728.blog.163.com/blog/static/3957072820091116114655254/vector典型的序列容器,C++标准严格要求次容器的实现内存必须是连续的,唯一可以和标准C兼容的stl容器,任意元素的读取、修改具有常数时间复杂度,在序列尾部进行插入、删除是常数时间复杂度,但在序转载 2011-10-28 10:57:47 · 787 阅读 · 0 评论 -
c++ 参数个数不确定
#include #include #include "stdarg.h"using namespace std;struct Params { enum ParamsType{NILL,INT,CHAR,DBL}; ParamsType type; union { int noParams; int intParams; char char原创 2011-12-10 15:11:54 · 2925 阅读 · 1 评论 -
<类模板 的 成员函数的特化>及<类 的 成员模板函数的特化>
#include "stdio.h"template class Sample{public: void print() {printf("print template\n");}};void Sample::print() {printf("print int\n");};// 调用int main(){ Sample a; a.print(); Sample转载 2012-01-09 09:47:24 · 2069 阅读 · 0 评论 -
空指针为什么能调用成员函数?(转载)
发现了一个空指针调用函数成功的例子,很奇怪就查了一下资料,如下:举个简单的例子,假如有如下的一段代码:class MyClass{public: int i; void hello() { printf("hello\n"); } void print() { printf("%d\n", i);转载 2012-01-09 11:29:33 · 2579 阅读 · 0 评论 -
类成员函数指针的用法
#include #include using namespace std;class Test{public:Test(){};virtual ~Test(){};void Handle(){printf("OK!\n");};};typedef void (Test::*Function)() ;int main(){Test* test = new原创 2011-11-24 10:16:09 · 441 阅读 · 0 评论 -
const成员函数
#include using namespace std; class Widget { public: Widget(int value):m_value(value){} int GetValue()const // 成员函数的const版本 { cout << "IN : int GetValue()const" << endl;原创 2012-01-14 18:49:36 · 684 阅读 · 0 评论 -
C++ Union联合的用法
#include using namespace std;struct Params{ enum ParamsType{INT,CHAR,DBL}; ParamsType type; union { int intParams; char charParams; double doubleParams; }; Params(int p){intParams = p;原创 2011-12-08 23:28:09 · 889 阅读 · 0 评论 -
PIMPL 模式的实现及应用。
看一些开源库,里面好多类有一个**IMPL。经查询还是有些门道和说法的。查询了一些相关资料。(英文没有翻译,挺简单的。)PIMPL 也可以称为一种设计模式了。现在摘录如下:pimpl 手法在 C++ 里已是“高手”们广泛运用的成熟方法之一,它的优点很多,诸如降低编译依赖、提高重编译速度之类的工具性优势自不待赘言,而其对“保持接口稳定性”的优点更值得称道。It makes it po转载 2012-01-04 13:41:42 · 854 阅读 · 2 评论 -
cout 格式化输出
转载自:http://www.cnblogs.com/walfud/articles/2047096.html将 cout 的 flag 保存到变量, 以便修改后的恢复 ostream::fmtflags old = cout.flag() ; // 无参将返回当前 flag 值 cout.flag(old) ;转载 2012-02-19 00:42:25 · 1288 阅读 · 0 评论 -
线程本地存储实例
// Copyright (C) 2001-2003// William E. Kempf//// Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0转载 2017-05-12 10:40:03 · 381 阅读 · 0 评论