- 博客(20)
- 资源 (8)
- 收藏
- 关注
原创 用visual studio 2008 (vs 2008) 统计源代码行数的 小技巧
<br />像用Eclipse 一样, 用vs 里的“查找”功能(直接按ctrl+H即可)<br /> <br />点上“使用“ 选”通配符“,<br /> <br />在”查找内容" 框里 右边的 小箭头的“表达式生成器” > 里 选“转义字特殊字符” <br /> <br />然后按“全部替换”<br /> <br />这时,系统就会提示替换了多少个结果,那个就是你的源代码总行数。<br /> <br />然后按 ctrl + Z 还原到替换成的代码<br /> <br /> <br /> <br />
2010-12-28 21:23:00 4096 2
原创 c风格:用简单的数据结构表示复杂的数据结构,效率会高很多
我在写一个哈夫曼编码解压缩文本文件时,遇到需要用一个数据结构来表示哈夫曼树的问题一开始我是用面向对象的方法,采用最直观的建模方法,即链式存储结构:template class BiTreeNode{private: BiTreeNode* leftChild; BiTreeNode* rightChild;public: T data; BiTreeNode():leftChild(NULL),rightChild(NULL) {}; BiTreeNode(T ite
2010-12-24 16:24:00 1272
原创 fstream与 C 风格(例如fread 和 fwrite )两种读写文件方法的效率比较
为了探录c++ 风格的fstream与 C 风格(例如fread 和 fwrite )两种读写文件的方法的效率,我特意做了两个实验。我的机器是Windows XP, Visual Studio 20081. 测试写文件速度程序设计思路: 将TEST_SIZE个字符用两种方式写入文件,记录两种方式的耗时。实验代码:void test_write(){ const int TEST_SIZE = 10000000 ; const char* c_plus_write_file = "H://c_p
2010-12-21 10:08:00 11967 6
原创 用ifstream 打开乱码的文件时,要用二进制的读取方式
<br /><br />ifstream ifstr(fn,ios::binary);<br /> <br />string line;<br />while( !ifstr.eof())<br />{<br />getline(ifstr,line);<br />len += line.length();<br />}
2010-12-20 11:50:00 2454
原创 stack overflow 的解决
<br />在写这个文件压缩器时, <br /> <br />我用fwrite 写了以<br /> <br />const int BUF_SIZE = 1024 * 1000 ;<br />char buf[BUF_SIZE];<br /> <br /> <br />FILE* fp = fopen(“data.txt","r");<br /> <br />int len = fread(buf, 1 , BUF_SIZE, fp);<br /> <br />这里的BUF_SIZE设置得太大,导致局部变量
2010-12-20 10:19:00 844
原创 在Ascii 码表内,还有几个类似于 LF (NL line feed, new line) 换行键这样的字符要作特殊处理
如题,附ascii码表的 地址:http://baike.baidu.com/view/15482.htm
2010-12-20 00:30:00 2175
转载 探寻C++最快的读取文件的方案(转)
转载自:http://www.byvoid.com/blog/fast-readfile/在竞赛中,遇到大数据时,往往读文件成了程序运行速度的瓶颈,需要更快的读取方式。相信几乎所有的C++学习者都在cin机器缓慢的速度上栽过跟头,于是从此以后发誓不用cin读数据。还有人说Pascal的read语句的速度是C/C++中scanf比不上的,C++选手只能干着急。难道C++真的低Pascal一等吗?答案是不言而喻的。一个进阶的方法是把数据一下子读进来,然后再转化字符串,这种方法传说中很不错,但具体如何从没试过,因
2010-12-18 19:56:00 971 1
转载 c++文件操作转贴(未整理)
fopen fdopen freopen 的区别2007-01-31 14:57#include FILE *fopen(const char *path, const char *mode); FILE *fdopen(int fildes, const char *mode); FILE *freopen(const char *path, const char *mode, FILE *stream); DESCRIPTION 描述函数 fopen 打开 一个 文件,
2010-12-18 19:49:00 1082
原创 如何将单个char c转成string
<br />由于string 是没有类似于 string(char c); 的构造函数的,所以思路是把char转成char* 或 char[], 再用string 的构造函数string(char*) 构造string <br /> <br />示例代码如下:<br /> <br /> <br />char c = 'a' ;<br /> <br />char tmp[1];<br /> <br />tmp[0] = c ;<br /> <br />string result(tmp,1); //要用第二个
2010-12-17 22:17:00 2607
原创 std list 的使用总结
<br /> <br />因为之前老忘记list的用法,造成时间浪费,故此总结,以后不再犯同样的错误<br /> <br />1. include 的文件<br /> <br />include <list><br />using namespace std;<br /> <br />2. 遍历<br /> <br />list<char> char_list;<br /> <br />for(list<char>::iterator it=char_list.begin(); it!=char_list.
2010-12-16 16:21:00 1531
原创 关于bitset
<br /> <br /> <br />bitset.at(0) ; 返回的是最低的二进制码<br /> <br />index 越小,位数越低<br />
2010-12-16 16:03:00 568
原创 写代码前要想好
写了一个文件压缩器,用哈夫曼编码,走了很多弯路,原因在于未能真正理解哈夫曼编的实质。1. 原来哈夫曼编码是可以连续在一起的。例如,'c'的编码是 01, b 的编码是 00, 那么字符串 'bc'的编码就是‘0001’, 注意,中间是不用空格或其他字符作为标识的。一开始我以为要,但未想清楚,直到看了书才知道。2. 出现这个的根本原因在于,过于匆忙地写代码,未能事先理解算法的本质。劳力是有限的,所以不能一味死干。聪明地干,先思考,再干活。
2010-12-15 22:07:00 701
转载 cout输出二进制数(转)
<br />#include <iostream>#include <bitset>using namespace std;int main(){ int i; cin>>i; cout<<"binary format of"<<i<<" is "<<bitset<sizeof(int)*8>(i)<<endl;} <br /> <br />C/C++里面只能支持八、十、十六进制三种<br />数字型常量。 <br /> <br /> 如果真
2010-12-13 15:35:00 3391 1
转载 cout输出16进制数(转)
<br />cout输出16进制2010-02-09 18:21<br />#include "stdafx.h"<br />#include "stdlib.h"<br />#include "iostream"<br />#include<iomanip> <br />using namespace std;<br />int _tmain(int argc, _TCHAR* argv[])<br />{<br />unsigned int i = 0;<br />int temp = (int)i
2010-12-13 15:29:00 3365
转载 STL中List 的sort 比较 用法示例
<br />#include <string>#include <list>#include <algorithm>#include <iostream>using namespace std;bool op(string str1, string str2){ return str1.length() < str2.length();}int main(int argc, char* argv[]) { list <string> list_sto
2010-12-13 15:17:00 1149
转载 STL中map用法详解(转)
<br /><br />Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有序的好处。<br />下面举例说明什么是一对一的数据映射。比如一个班级中,每个学生的学号
2010-12-13 10:23:00 631
原创 C++ 文件操作小结(1)
1. 创建文件//create a new fileFILE* f = fopen ( file_name , "a"); fclose(f); 具体参数用法,参见 http://baike.baidu.com/view/656681.htm2. 读入文件一行 getline 操作:ifstream ifstr(file_name);string line;while(!ifstr.eof()){ getline(ifstr,line);} 3. 文件的删除与重
2010-12-13 09:08:00 584
原创 在拷贝(复制)代码前,应该确呆所复制的代码是正确的
<br /> <br />1. 拷贝代码是很危险的,虽然提高了效率,但往往因为拷贝的目标位置 与 源位置相比,有不同的需求<br /> <br />我常常遇到这种情况:<br /> <br /> 1. 拷贝一段代码以后,对代码进行修改,但注释忘记修改了;于是以后回来看到这段 注释与代码 不致的程序时,很有可能我被注释误导了。<br /> <br /> 2. 如果拷贝的代码是不正确的,以后debug就要做很多件事情。
2010-12-12 16:34:00 965
原创 C++ : 重命名 及 删除文件 (C 风格)
函数名: rename 功 能: 重命名文件 用 法: int rename(char *oldname, char *newname); 程序例: #include int main(void) { char oldname[80], newname[80]; /* prompt for file to rename and new name */ printf("File to rename: ");
2010-12-12 15:43:00 2881
原创 C++: int to string
<br />1. 用strstream <br /> <br />#include <strstream>int hello=4;strstream ss;ss<<hello;string s=ss.str();//调用string的方法cout<<s.c_str()<<endl <br /> <br />2. 用itoa<br /> <br /> #include <stdlib.h>char buffer[20]; int i = 3445; _itoa
2010-12-12 15:41:00 781
托福OG(第三版) The.Official.Guide.to.the.TOEFL.iBT,Third.Edition
2010-07-23
Concrete Mathematics
2010-07-02
用Rational RequisitePro写用例规约(Use Case Specification)的心得
2009-11-11
Struts.The.Complete.Reference.2nd.Edition
2009-10-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人