代码改变世界

c++ 很多相关概念

2012-06-27 19:59 by youxin, 266 阅读, 0 推荐, 收藏,
摘要:下面的一个简单的继承:#include<iostream>using namespace std;class Animal{public: Animal(int height,int weight) { cout<<"animal construct"<<endl; } ~Animal() { cout<<"animal destruct"<<endl; }};class Fish:public Animal{public: Fish() { cout<<"fish con 阅读全文

c++ vector resize()和reserve()区别

2012-06-27 18:21 by youxin, 1178 阅读, 0 推荐, 收藏,
摘要:resize()是改变了size和capacity。void resize ( size_type sz, T c = T() );Change sizeResizes the vector to containszelements.Ifszis smaller than the current vectorsize, the content is reduced to its firstszelements, the rest being dropped. 如果sz小于现在的尺寸,内容减小到sz,其余 部分丢弃。Ifszis greater than the current vectors. 阅读全文

c++ 基类与派生类的构造函数

2012-06-23 00:01 by youxin, 373 阅读, 0 推荐, 收藏,
摘要:基类与派生的构造函数的调用顺序。创建时先基类后派生类。销毁时先派生类后基类。当有参数时,参数必须传送给基类。注意例子中传递的方法。#include <iostream>#include <string>using namespace std;class CBase { string name;public: CBase(string s) : name(s) { cout << "BASE: " << name << endl; } ~CBase() { cout << "~BASE" 阅读全文

c++ 模板函数remove()

2012-06-22 00:51 by youxin, 1461 阅读, 1 推荐, 收藏,
摘要:template ForwardIterator remove ( ForwardIterator first, ForwardIterator last, const T& value );注意返回迭代器。Remove value from rangeCompares the elements in the range[first,last)againstvalue, and removes those that compare equal from the resulting range. The resulting range co... 阅读全文

c++ vector 删除指定元素

2012-06-22 00:29 by youxin, 76325 阅读, 3 推荐, 收藏,
摘要:只使用vector的erase函数,记住,该函数是迭代器失效,返回下一个迭代器。#include #include using namespace std; int main(){ vector arr; arr.push_back(6); arr.push_back(7); ... 阅读全文

C++ string 比较

2012-06-21 22:19 by youxin, 45034 阅读, 0 推荐, 收藏,
摘要:传统的c字符串比较必须用strcmp函数:(不能用==,否则比较的只是两个地址)函数名: strcmp功 能: 串比较用 法: int strcmp(char *str1, char *str2);看Asic码,str1>str2,返回值 > 0;两串相等,返回0上面的头文件为<string.h> strncasecmp()是忽略大小写的。c++ string 类型的比较可以用string的函数compare()int compare ( const string& str ) const;int compare ( const char* s ) const; 阅读全文

汇编:将以0结尾的字符串转换为大写并输出

2012-06-18 16:03 by youxin, 714 阅读, 0 推荐, 收藏,
摘要:编程:将'welcome-to-masm! 转成大写并输出。要注意判断是否为小写字母,不为字母(-)就不要转换了。assume cs:codedata segment db 'welcome-to-masm!',0 data endscode segmentstart: mov ax,data mov ds,ax mov si,0 ;ds:si 指向字符串 call captital mov dh,12 mov dl,0 mov cl,2 call show_str mov ax,4... 阅读全文

c++ distance 和advance函数

2012-06-16 22:47 by youxin, 8763 阅读, 0 推荐, 收藏,
摘要:distance主要是用来求两个迭代器之间的元素个数。template<class InputIterator> typename iterator_traits<InputIterator>::difference_type distance (InputIterator first, InputIterator last);Return distance between iteratorsCalculates the number of elements betweenfirstandlast.Ifiis aRandom Access Iterator, the f 阅读全文

c++ fill 和fill_n

2012-06-16 22:30 by youxin, 656 阅读, 0 推荐, 收藏,
摘要:template < class ForwardIterator, class T > void fill ( ForwardIterator first, ForwardIterator last, const T& value );Fill range with valueSetsvalueto all elements in the range[first,last).fill_n函数模板如下:template < class OutputIterator, class Size, class T > void fill_n ( OutputIterato 阅读全文

vs 在watch监视窗口 vector 错误 :overloaded operator not found

2012-06-15 13:42 by youxin, 1252 阅读, 0 推荐, 收藏,
摘要:一下的代码,debug显示是正常的。如果你调试时,查看watch窗口会发现一个错误:overloaded operator not found找不到重载运算符#include<iostream>#include<vector>#include<string>using namespace std;int main(){ vector<vector<string> > vec; vector<string> vec1,vec2; vec1.push_back("can"); vec1.push_back( 阅读全文
上一页 1 ··· 228 229 230 231 232 233 234 235 236 ··· 269 下一页