
C/C++ Basic
文章平均质量分 54
begges
喜欢编程,玩儿,学习,运动。
展开
-
全排列算法实现
今天跟同事讨论到全排列算法,即n个数任意排列,但不能有重复的数,将所有的排列列出。#include "stdafx.h"#include #include using namespace std;templatevoid swap(T *a, T *b){ T t = *a; *a = *b; *b = t;}templatevoid Permutation(vector &data, typename vector::size_type star原创 2010-07-28 18:02:00 · 693 阅读 · 0 评论 -
由数组的下表得到长度
<br />已知数组下表i和j(i < = j),问i到j的长度是多少(包括i和j)?<br />计算方法如下:<br />len = j - i + 1<br /> <br />例子:strFileName是一个包含后缀名,不包含路径的文件名(如:river.jpg),下面的代码能够得到它的后缀名:<br /> <br /> string strExtension;<br /> string::size_type posDot = strFileName.find_last_of('.');<br />原创 2011-01-12 13:58:00 · 691 阅读 · 0 评论 -
通过手机键盘将字符串转换为数字的小程序
<br />#include "stdafx.h"#include <iostream>#include <vector>#include <algorithm>#include <string>int _tmain(int argc, _TCHAR* argv[]){ bool br = true; vector<string> vecPhotoNumber; vecPhotoNumber.push_back("abc"); vecPhotoNumber.pus原创 2011-01-04 18:28:00 · 1142 阅读 · 0 评论 -
如何修改一个文件的内容。
<br />1. 一次全部读出到内存,在内存中修改后,存回到原来的文件里。<br /> <br />原创 2010-10-22 11:41:00 · 816 阅读 · 0 评论 -
使用fstream创建文件
<br />有网上说,使用fstream file(path.c_str());语句,也就等于fstream file(path.c_str(), ios::in | ios::out);语句可以创建文件。但我发现不可以,如果想创建文件,必须向下面这样才行:<br /> <br />fstream out_file;out_file.open(path.c_str(), ios::out);// 在这里使用 ios::out | ios::in 也不能创建文件//执行到此,如果文件不存在,则创建原创 2010-10-22 10:41:00 · 9738 阅读 · 3 评论 -
文件结束符eof的正确使用
问题:来自:http://topic.youkuaiyun.com/u/20100103/00/99f1111e-aebc-496d-bcb2-889bbe82f091.html如下:#include #includeusing namespace std;int main() {ofstream ofs("a.txt");int n = 10;while (--n) ofs>x; ++z; cout原创 2010-10-21 15:59:00 · 5514 阅读 · 0 评论 -
const关键字在类的成员函数上的应用(1)
<br /> <br />先看下面类的定义 (编译通过):<br />class Hand{public: Hand() { }private: vector<wstring> _fingers; wstring _color;public: const vector<wstring> & fingers() const { return _fingers; } const wstring & color() const { return _color; }原创 2010-10-20 18:20:00 · 689 阅读 · 0 评论 -
const关键字在类的成员函数上的应用(2)
<br />const修饰的引用作为函数的返回值的一个好处如下:<br />class Error{public:const string & Message() { return _message; }void Message(const string &value) { _message = value; }private:string _message;}void display(const string &info){ cout << info <<原创 2010-10-20 18:24:00 · 573 阅读 · 0 评论 -
理解 typename关键字
<br />本文来自:http://dev.yesky.com/13/2221013.shtml<br /> <br />C++箴言:理解typename的两个含义 2005-12-05 09:14作者:fatalerror99出处:BLOG责任编辑:方舟问题:在下面的 template declarations(模板声明)中 class 和 typename 有什么不同? <br /><br />template<class T> class Widget; // uses "class"转载 2010-09-07 16:45:00 · 733 阅读 · 0 评论 -
Trie 树
Trie,又称单词查找树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。Trie 取自 Retrieve 中间四个字母。下面是来自http://zh.wikipedia.org/zh-cn/Trie的一个例子:#include #include #include #define TREE_WIDTH 256 #define WORD转载 2010-09-07 16:43:00 · 688 阅读 · 0 评论 -
C预定义
<br />C标准中指定了一些预定义的宏<br /> __DATE__<br /> 进行预处理的日期(“mm dd yyyy”形式的字符串文字)<br /> __TIME__<br /> 源文件编译时间,格式微“hh:mm:ss”<br /> __FILE__<br /> 代表当前源代码文件名的字符串文字<b转载 2010-08-18 14:28:00 · 1109 阅读 · 0 评论 -
经典编程:DLL地狱及其解决方案 文章出处:飞诺网(www.diybl.com):http://www.diybl.com/course/3_program/vc/vc_js/20100630/26
原作者:Ivan S Zapreev 译者:陆其明 概要 本文将要介绍DLL的向后兼容性问题,也就是著名的“DLL Hell”问题。首先我会列出自己的研究结果,其中包括其它一些研究者的成果。在本文的最后,我还将给出“DLL Hell”问题转载 2011-09-06 13:11:24 · 1302 阅读 · 0 评论