
VC++学习笔记
文章平均质量分 67
ctg168
这个作者很懒,什么都没留下…
展开
-
VC++ 的this关键字
每个成员函数中都隐含包含一个this指针作为函数桉树,并在函数调用时将对象自身的地址隐含作为实际参数传递#include "stdafx.h"#include "string.h"class CBook{public: int m_Pages; /* 每个成员函数中都隐含包含一个this指针作为函数桉树,并在函数调用时将对象自身的 地址隐含作为实际参数传递 这个方法原创 2015-06-05 15:02:51 · 863 阅读 · 0 评论 -
VC++ 输入流迭代器
输入一些单词,中间使用空格分隔,最后统计每个单词出现的次数。#include "stdafx.h"#include #include #include #include #include #include #include using std::cin;using std::cout;using std::endl;using std::tuple;using st转载 2015-06-10 13:40:06 · 573 阅读 · 0 评论 -
VC++ 使用 typedef, Tuple, Array 来模拟一个对象的列表,并对列表进行增减、赋值和访问,
下面是综合例子:#include "stdafx.h"#include #include #include #include #include using std::cout;using std::endl;using std::tuple;using std::string;using std::setw;using std::get;const size_t原创 2015-06-09 16:47:54 · 634 阅读 · 0 评论 -
VC++ 字符串赋值例子(2)
本例中,讲了两点,一个是字符串赋值,一个是vector链表的迭代访问。#include "stdafx.h"#include #include #include using std::cout;using std::endl;using std::vector;class CNode{private: char* firstName;public: CNode(con原创 2015-06-09 15:25:31 · 1159 阅读 · 0 评论 -
VC++ unique_ptr的使用例子
下面是代码示例:#include "stdafx.h"#include #include using std::cout;using std::cin;using std::endl;using std::unique_ptr;unique_ptr treble(double);int main(int argc,_TCHAR* argv[]){ double原创 2015-06-09 11:10:30 · 967 阅读 · 0 评论 -
vc++ 的指针和数组结合理解的最佳例子
下面的方法先接受用户的输入(不超过80个字符),然后计算输入的字符的长度:#include "stdafx.h"#include #include #include using std::cout;using std::cin;using std::endl;using std::setw;int main(int argc,_TCHAR* argv[])原创 2015-06-08 16:50:05 · 2054 阅读 · 1 评论 -
VC++ 完整的例子(电话本管理)
文件一:Person.h//Person.h#pragma once#include using std::string;class Person{public: Person(const string& first="",const string& second="") :firstname(first),secondname(second){ } Pers翻译 2015-06-09 17:36:36 · 588 阅读 · 0 评论 -
vector 用法之:顺向和逆向
要使用迭代器访问矢量中的元素,但不希望修改元素是,可以使用cbegin和cend函数,他们返回const迭代器。#include "stdafx.h"#include #include using std::cout;using std::endl;using std::vector;int main(int argc,_TCHAR* argv[]){ int n[]={1原创 2015-06-09 11:44:31 · 2008 阅读 · 0 评论 -
VC++ 字符串赋值例子
VC++ 字符串赋值例子。原创 2015-06-09 15:03:12 · 2554 阅读 · 0 评论 -
vc++ PushBack 和 Assign 的示例
开门见山,先看例子:#include "stdafx.h"#include #include using std::cout;using std::endl;using std::vector;int main(int argc,_TCHAR* argv[]){ vector values; for(int i=1;i<=5;i++) values.push_back(原创 2015-06-09 14:46:27 · 572 阅读 · 0 评论 -
C++ 函数模板示例 2 (配合decltype)
#include "stdafx.h"#include #include #include #include using std::cout;using std::cin;using std::endl;using std::setw;template auto product(T1 v1[], T2 v2[], size_t count) -> decltype(v1[0原创 2015-06-08 18:44:45 · 953 阅读 · 1 评论 -
VC++ 里面的_tmain 和 main的区别
VC++ 里面的_tmain 和 main的区别原创 2015-06-08 14:46:20 · 9991 阅读 · 2 评论 -
C++友元函数(有缘分,咋都行!)
酒逢知己么么哒,话不投机呵呵呵。有缘分,就可以任性!#include "stdafx.h"#include "string.h"class CItem{ //只让名为"OutputItem(CItem *pItem)"的这个函数访问自己的私有对象, //但是如果OutputItem这个函数没有定义,这里也不会报错. friend void OutputItem(CIt原创 2015-06-05 15:26:15 · 560 阅读 · 0 评论 -
C++运算符重载
#include "stdafx.h"#include "string.h"class CBook{public: int m_Pages; CBook operator+(const CBook &book) { CBook bk; bk.m_Pages = m_Pages + book.m_Pages; return bk; } CBook operator+原创 2015-06-05 15:09:17 · 584 阅读 · 0 评论 -
C++ 复制构造函数
#include "stdafx.h"#include "string.h"class CBook{public: char m_BookName[128]; const unsigned int m_Price; int m_ChapterNum; CBook() :m_Price(32),m_ChapterNum(15) { strcpy_s(m_BookName,"原创 2015-06-05 14:29:09 · 431 阅读 · 0 评论 -
C++函数模板
函数模板很类似于C#的泛型,有木有?模板定义:template type Sum(type xvar, type yvar){ return xvar+yvar;}模板定义二:template type GetMax(type array[len]){ type ret=array[0]; for(int i=1;i<len;i++){ ret = (原创 2015-06-05 13:25:35 · 417 阅读 · 0 评论 -
[Windows编程] Windows最常见的数据类型列表
转载 2015-06-11 14:43:14 · 468 阅读 · 0 评论