
码头仓库
文章平均质量分 65
LaPizza
Its my way!
展开
-
常用HASH函数
//对len长度的字符串进行hashunsigned int HashCode(const char* str, int len){ unsigned int hash = 0; while (*str && len > 0) { hash = (*str++) + (hash << 6) + (hash << 16) - has原创 2009-12-31 10:49:00 · 1046 阅读 · 0 评论 -
用stringstream实现了任意类型变量的相互转换
在完全不用考虑效率的情况下,字符串流的确是个好东西。可以很方便的进行变量类型转换。下面的typeTrans函数便实现了任意类型变量的相互转换。如果需要实现类对象的转换,只需重载 “>”两个operator就行了。 #include #include using namespace std;templateint typeTrans(T1& in, T2& out原创 2010-04-14 13:45:00 · 567 阅读 · 0 评论 -
用std::find查找文件流中的内容
在一般的情况下, 我是很少使用迭代器istream_iterator的。最近在为项目编写一个读特定格式文件的功能时,发现使用istream_iterator和std::find能非常方便的实现文件内容的查找。注:以下全部假定是文本文件,二进制文件没有测试过。 假定要查找的是一个文件中的某个string,可以这样实现: ifstream fIn("yourfile");转载 2010-04-13 17:16:00 · 841 阅读 · 0 评论