c/c++
文章平均质量分 72
knight_yzzz
专注于android的爱好者
展开
-
金山题
Welcome To Kingsoft姓名: 林道疆 日期: 2007年8月17日 答题时间: 一、请你就C/C++或者JAVA代码行数、注释行数统计工具的实现,描述一下:1、 需要考虑哪些过滤条件?你如何处理?答:过滤条件:(取得每行并去掉两头的空格后)⑴空行,行的长度为0;⑵如果是以//开头,为注释行;⑶//在行中,并判断不是在字符串中,即“”中,为代码+注释混合行,//在“”中时为代码行;转载 2013-10-14 20:55:38 · 951 阅读 · 0 评论 -
INI文件的读取
//处理一般的配置文件 例如ini 文件#include #include #include using namespace std;//使用vecotr 必须包含下面两句话#include using std::vector;#include using std::map;class IniFile{ public: IniFi原创 2013-05-28 23:11:58 · 524 阅读 · 0 评论 -
c++ 常用查询类
#include class textquery{public: typedef std::string::size_type str_size; typedef std::vector::size_type line_no; //size_type相当于 unsigned int void readfile(std::ifstream &in) { //先存储原创 2013-05-28 23:10:56 · 755 阅读 · 0 评论 -
cstring类的正确写法
#include class String{ private: char *m_data; // 用于保存字符串 typedef unsigned int size_type; public: String(const char *str = NULL);原创 2013-05-28 23:02:03 · 604 阅读 · 0 评论 -
QUEUE c++查询
template //#define MAXSIZE 512class Queue{ private: int front ; int rear; int count; //此处只是声明,在类外定义 //规范:限制将一个 constant(常量)的作用范围限制在一个 class(类)内 st原创 2013-05-28 23:23:46 · 787 阅读 · 0 评论 -
c++虚基类
class Endangered {public: typedef enum Status{ critical, environment, improving }STATUS; Endangered(STATUS state):animal_status(state){} virtual ~Endangered(){} virtual std::ostream & pr原创 2013-05-28 22:21:11 · 593 阅读 · 0 评论 -
c++学习看看
#include #include class Sales_item {friend bool operator==(const Sales_item&, const Sales_item&);// other members as beforepublic: // added constructors to initialize from a string or a原创 2013-05-28 23:28:47 · 484 阅读 · 0 评论 -
c++ stack
template class Stack{ private: enum { MAXSIZE=128 }; T stacklist[MAXSIZE]; int top;public : void push(const T&item); Stack & operator =(Stack const & src); T pop(void); S原创 2013-05-28 23:26:08 · 524 阅读 · 0 评论 -
类似于android 的ref基类对引用计数作用
using std::out_of_range;class CheckedPtr {public: CheckedPtr(int * a,int *b,int *c):begin(a),end(b),curr(c){} int& operator*(); const int& operator*() const; CheckedPtr& operator++();原创 2013-05-28 23:21:33 · 1165 阅读 · 0 评论 -
c++list 类
template class Node{ public: Node*next; T data; Node(const T & item, Node*pnext=NULL):data(item):next(pnext){} Node *NextNode(void) const;}; template Node *原创 2013-05-28 23:04:33 · 3978 阅读 · 0 评论 -
mem分配 在c++中写法
class CBuffer{ char * m_pBuffer; int m_size;public: CBuffer() { m_pBuffer=NULL; } ~CBuffer() { Free(); } void Allocte(int size) {原创 2013-05-28 22:56:06 · 1032 阅读 · 0 评论 -
vector 学习
#if 0template class vector {public : vector():elements(NULL):first_free(NULL):end(NULL){} void push_back(const T &); void reserve(const size_t n); T & operator [](const size_t index)原创 2013-05-28 22:34:56 · 520 阅读 · 0 评论 -
c++学习
Const :非const的全局变量在整个程序中都可以访问,加上const限定符呢? 答:使用修饰符 extern const可以再全局访问。什么是引用?定义的类似于: int & ref=val;当引用捆绑于实际对象,对引用的操作即对实际对象的操作。ref +=2即val+2;当引用初始化之后,只要该引用存在,它就保持绑定到初始化时指向的对象。那什么是const 引用原创 2013-05-26 20:49:08 · 533 阅读 · 0 评论 -
effect c++ 1 const and enum
#define ASPECT_RATIO 1.653 没有被加入 symbol table(符号表)。解决方案是用 constant(常量)来取代 macro(宏):const double AspectRatio = 1.653; // uppercase names are usually for //原创 2013-04-17 23:37:08 · 641 阅读 · 0 评论 -
c 缺陷和陷阱
《C陷阱与缺陷》读书笔记前记2010年上半学期软件学院课程不是太多,有了很多空余时间,于是利用一个月的时间把《C陷阱与缺陷》这本书看了一遍。正如ACCU主席Francis Glassborow所说“本书所提示的知识,至少能够帮助你减少C代码和初级C++代码中90%的Bug”,这本书真的是C和C++方面的经典书籍。原创 2013-03-20 22:48:03 · 622 阅读 · 0 评论 -
面试要看的
面试题1.链表和数组的区别在哪里? 2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法? 4.请编写能直接实现strstr()函数功能的代码。 5.编写反转字符串的程序,要求优化速度、优化空间。 6.在链表里如何发现循环链接? 7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。 8原创 2013-03-20 22:46:03 · 563 阅读 · 0 评论 -
c++ 动态加载
VC里面实现动态对象载入已经不是什么新鲜事情了,很多的plug-in技术就是例子。Unix下,通过动态载入so获得一个对象也不是什么难事,不过对这个对象的管理就是一件比较麻烦的事情了。一般的需求如下: 有class TMyObj,准确说TMyObj应该是一个接口,根据不同具体情况会有不同的实现,例如 TMyObj1、TMyObj2等等……而这些TMyObj1和TMyObj2分别保存在不同的s转载 2013-03-20 22:43:22 · 2145 阅读 · 0 评论 -
map 学习
class textquery{public:typedef std::vector::size_type line_no;void read_file(std::ifstream &is){store_file(is);build_map();}std::setrun_query(const std::string &) const;std::string t原创 2013-05-29 20:04:18 · 554 阅读 · 0 评论 -
c++ 基础巩固
#include #include #include template inline T max(const T &A,const T &B) { if(A>B) return A;else return B; } inline char const *maxstr(char const *a,char const *b)原创 2013-05-29 20:15:03 · 624 阅读 · 0 评论 -
深入分析Windows和Linux动态库应用异同
深入分析Windows和Linux动态库应用异同 摘要:动态链接库技术实现和设计程序常用的技术,在Windows和Linux系统中都有动态库的概念,采用动态库可以有效的减少程序大小,节省空间,提高效率,增加程序的可扩展性,便于模块化管理。但不同操作系统的动态库由于格式 不同,在需要不同操作系统调用时需要进行动态库程序移植。本文分析和比较了两种操作系统动态库技术,并给出了将Visual C+转载 2013-10-14 20:22:18 · 712 阅读 · 0 评论 -
关于词典查询的一点思路
词典查询方法:首先,编写加入词库工具,读文件,每行对应单词为中文单词和英文单词,录入时这样:id=0 a 中文单词,同时,写另一个索引文件2 英文单词首地址,中文单词首地址。当输入一个字母时,开启另一个线程去查找,把这个单词,根据ID二分之后 即 currentId=0+max/2;而这个currentId可以通过索引文件的固定格式计算出它的地址,在此地址上存放的是current转载 2013-10-09 19:19:20 · 775 阅读 · 0 评论 -
c++面试题
某IT外企面试题:二分法求方程!看看大家的C++功底!!//f(x)=RMAX-R+(R-r)*double (cos(0.5*x))+double (sqrt(r*r-(R-r)*(R-r)* sin(0.500*x)* sin(0.500*x))) 请用二分法或其他方法求出解x.要求精度esp=1e-5 其中RMAX,R,r从键盘输入。原创 2013-07-06 10:55:08 · 681 阅读 · 0 评论 -
哈夫曼的c语言实现
我们设置一个结构数组 HuffNode 保存哈夫曼树中各结点的信息。根据二叉树的性质可知,具有n个叶子结点的哈夫曼树共有 2n-1 个结点,所以数组 HuffNode 的大小设置为 2n-1 。HuffNode 结构中有 weight, lchild, rchild 和 parent 域。其中,weight 域保存结点的权值, lchild 和 rchild 分别保存该结点的左、右孩子的结点在数组原创 2013-06-22 15:35:19 · 810 阅读 · 0 评论 -
c++ 通用handler
template class Handle {public: // unbound handle Handle(T *p = 0): ptr(p), use(new size_t(1)) { } // overloaded operators to support pointer behavior T& operator*(); T* o转载 2013-06-16 12:09:37 · 1606 阅读 · 0 评论 -
c++学习之模板类
template class Queue {public: Queue(); // default constructor Type &front(); // return element from head of Queue const Type &front() const; void p转载 2013-06-15 20:06:13 · 611 阅读 · 0 评论 -
c++学习之通用句柄的使用
// private, abstract class acts as a base class for concrete query typesclass Query_base { friend class Query; Query 类的虚函数要访问Query_base,所以在Query_base 声明友元类protected: typedef TextQuery::原创 2013-06-14 23:01:04 · 1052 阅读 · 0 评论 -
消息处理实例
#include "Folder.h"#include using std::cerr; using std::endl;using std::set; using std::string; using std::vector;#include #include #include class Folder;class Message { friend cl原创 2013-06-13 17:19:34 · 700 阅读 · 0 评论 -
c面试
.在函数 void func(int *a[10]) 和 void func(int **a)是等价的吗?void func(int *a[10])和void func(int **a)//前者是数组指针,后者是二级指针void print(char **pstr) 和 void print(char *pstr[3])等价{int i;puts(pstr[0]);//fo原创 2013-06-02 15:36:58 · 1481 阅读 · 0 评论 -
c++面试
C++: 考察作用域问题: #include using namespace std; class A {public: A() {cout ~A() { cout private: int a; }; int main() { A *p ; { A *p;原创 2013-06-02 15:33:55 · 565 阅读 · 0 评论 -
c++泛型算法
#include "algs_preamble.h"#include using std::ifstream;#include using std::size_t;// comparison function to be used to sort by word lengthbool isShorter(const string &s1, const string &s2)原创 2013-05-31 22:46:43 · 569 阅读 · 0 评论 -
c++ 学习之2
int main(){ // map from author to title; there can be multiple titles per author multimap authors; // add data to authors //pair("Alain de Botton", "book1") pair的创建和初始化 auth原创 2013-05-31 21:21:23 · 566 阅读 · 0 评论 -
C++之智能指针
#include using std::ostream; using std::cout; using std::endl;#include class HasPtr {public: // no point to passing a pointer if we're going to copy it anyway // store pointer to a c原创 2013-05-31 23:58:39 · 510 阅读 · 0 评论 -
类之间的关系
原创 2013-06-08 21:08:14 · 706 阅读 · 0 评论 -
c++学习之单词查询2
#ifndef TEXTQUERY_H#define TEXTQUERY_H#include #include #include #include #include #include #include #include class TextQuery {public: // typedef to make declarations easier原创 2013-05-29 23:24:55 · 856 阅读 · 0 评论 -
c++ map学习之单词查询
#ifndef TEXTQUERY_H#define TEXTQUERY_H#include #include #include #include #include #include #include #include #include #include #include #include #include #include #inc转载 2013-05-29 22:31:07 · 757 阅读 · 0 评论 -
考题
1、局部变量能否和全局变量重名?答:能,局部会屏蔽全局。要用全局变量,需要使用/"::/"局部变量可以与全局变量同名,在... 华为经典C&C++ 笔试题(1、局部变量能否和全局变量重名?答:能,局部会屏蔽全局。要用全局变量,需要使用/"::/"局部变量可以与全局变量同名,在函数内引用这个变量时,会用到同名的局部变量,而不会用到全局变量。对于有些编译器而言,在同一个函数内可以定义多原创 2009-07-16 11:24:00 · 515 阅读 · 0 评论 -
c
切记strcpy()函数的使用要注意两点:第一个参数的空间要大于第二个参数的空间。第二个参数一定要包含 '/0' 结束符重解几道华为经典C语言面试题1、找错 这里string数组越界,因为字符串长度为10,还有一个结束符’/0’。所以总共有11个字符长度。string数组大小为10,这里越界了。PS:使用strcpy函数的时候一定要注意前面目的数组的大小一原创 2009-07-16 11:29:00 · 421 阅读 · 0 评论 -
字符串,注意!!
字符串使用注意事项:char str1[] = "abc";char str2[] = "abc";const char str3[] = "abc";const char str4[] = "abc";const char *str5 = "abc";const char *str6 = "abc";char *str7 = "abc";char *str8 =原创 2013-02-01 11:53:48 · 521 阅读 · 0 评论 -
extern “C” 知多少
1,extern “C” c中怎样调用c++函数。在.CPP中:void func(){ printf("hello world");}在其头文件中:extern "C" { 表示让func()不按照cpp函数编译,而按照c函数编译。void func();}在调用其函数的c文件中 先声明extern void func();原创 2013-01-30 22:22:50 · 560 阅读 · 0 评论 -
istringstream
#include #include #include using namespace std;int main(int argc, char *argv[]){ string str,line; while(getline(std::cin,line)) { long l=0; istringstream s(line);//istringstre原创 2013-02-02 10:28:03 · 344 阅读 · 0 评论