C++标准库(STL)的几种数据类型
一.字符串类型:
1 支持用字符序列或第二个字符串对象来初始化一个字符串对象,C 风格的字符串不支持用另外一个字符串初始化一个字符串.
2 支持字符串之间的拷贝.C 风格字符串通过使用库的数strcpy()来实现.
3 支持读写访问单个字符.对于C 风格字符串单个字符访问由下标操作符或直接解除指针引用来实现.
4 支持两个字符串的相等比较.对于C 风格字符串字符串比较通过库函数strcmp()来实现
5 支持两个字符串的连接,把一个字符串接到另一个字符串上或将两个字符串组合起来形成第三个字符串.对于C 风格的字符串连接由库函数strcat()来实现,把两个字符串连接起来形成第三个字符串的实现是用trcpy()把一个字符串拷贝到一个新实例中然后用strcat()把另一个字符串连接到新的实例上
6 支持对字符串长度的查询(.size()).对于C 风格字符串字符串长度由库函数strlen()返回
7 支持字符串是否为空的判断(调用.empty())对于C 风格字符串通过下面两步条件测试来完成
二.const类型
const double *cptr;
cptr 是一个指向double 类型的const 对象的指针.我们可以从右往左把这个定义读为(cptr 是一个指向double 类型的被定义成const 的对象的指针),此中微妙在于cptr 本身不是常量,我们可以重新赋值cptr 使其指向不同的对象,但不能修改cptr 指向的对象.在实际的程序中指向const 的指针常被用作函数的形式参数它作为一个约定来保证,被传递给函数的实际对象在函数中不会被修改.
int errNumb = 0;
int *const curErr = &errNumb;
curErr 是指向一个非const 对象的const 指针.我们可以从右拄左把定义读作(curErr是一个指向int 类型对象的const 指针).这意味着不能赋给curErr 其他的地址值但可以修改curErr 指向的值.
指向const 对象的const 指针的定义就是将前面两种定义结合起来.例如
const double pi = 3.14159;
const double *const pi_ptr = π
在这种情况下pi_ptr 指向的对象的值以及它的地址本身都不能被改变.我们可以从右往左将定义读作:i_ptr 是指向被定义为const 的double 类型对象的const 指针.
三.引用类型:
通过引用我们可以间接地操纵对象使用方式类似于指针但是不需要指针的语法在实际的程序
中引用主要被用作函数的形式参数——通常将类对象传递给一个函数.引用类型由类型标识符和一个取地址操作符来定义引用必须被初始化.引用的所有操作实际上都被应用在它所指的对象身上包括取地址操作符.
const 引用可以用不同类型的对象初始化,只要能从一种类型转换到另一种类型即可也可以是不可寻址的值.
四.vector容器:
vector< int > ivec( 10, -1 );
定义了ivec 它包含十个int 型的元素每个元素都被初始化为-1;
一般我们不是定义一个已知大小的vector 而是定义一个空vector,vector< string > text;
string word;
while ( cin >> word ) {
text.push_back( word );
// ...
}
虽然我们仍可以用下标操作符来迭代访问元素
cout << "words read are: n";
for ( int ix = 0; ix < text.size(); ++ix )
cout << text[ ix ] << ' ';
cout << endl;
但是更典型的做法是使用vector 操作集中的begin()和end()所返回的迭代器iterator
对
cout << "words read are: n";
for ( vector<string>::iterator it = text.begin();
it != text.end(); ++it )
cout << *it << ' ';
cout << endl;
五.复数类型:
1。#include <complex>
2。复数对象的定义一般可以使用以下形式
aa.// 纯虚数0 + 7i
complex< double > purei( 0, 7 );
bb.// 用另一个复数对象来初始化一个复数对象
complex< double > purei2( purei );
cc. 以声明复数对象的数组
complex< double > conjugate[ 2 ] = {
complex< double >( 2, 3 ),
complex< double >( 2, -3 )
};
dd.声明指针或引用
complex< double > *ptr = &conjugate[0];
complex< double > &ref = *ptr;
volatile 限定修饰符:当一个对象的值可能会在编译器的控制或监测之外被改变时.例如一个被系统时钟更新的变量那么该对象应该声明成volatile .因此编译器执行的某些例行优化行为不能应用在已指定为volatile 的对象上.
volatile int display_register;//display_register 是一个int 型的volatile 对象.
volatile 修饰符的主要目的是提示编译器该对象的值可能在编译器未监测到的情况下被改变.因此编译器不能武断地对引用这些对象的代码作优化处理.
六.pair 类型:
pair 类也是标准库的一部分它使得我们可以在单个对象内部把相同类型或不同类型的两个值关联起来为了使用pair 类我们必须包含下面的头文件
#include <utility>
1.pair< string, string > author( "James", "Joyce" );
创建了一个pair 对象author. 它包含两个字符串分别被初始化为James 和Joyce.
我们可以用成员访问符号(member access notation )访问pair 中的单个元素,它们的名字为first 和second.
string firstBook;
if ( author.first == "James" &&
author.second == "Joyce" )
firstBook = "Stephen Hero";
2.一个元素持有对象的名字,另一个元素持有指向其符号表入口的指针:
// 前向声明(forward declaration)
class EntrySlot;
extern EntrySlot* look_up( string );
typedef pair< string, EntrySlot* > SymbolEntry;
SymbolEntry current_entry( "author", look_up( "author" ));
// ...
if ( EntrySlot *it = look_up( "editor" ))
{
current_entry.first = "editor";
current_entry.second = it;
}
七.类类型:
6 篇评论在 “C++标准库(STL)的几种数据类型”
2
匿名
08/01 2008, 13:53 Say: [回复]
soon as possible.level wow.Just remember that .
mp3 mp4 player.You will need to know .mp3 mp4
player.Below are things you wow.Such as,
mp3 players.I’m going to try to cover the dog
mp3 player.Remember , you will be there .sell wow
gold.1.
buy cheap wow gold.Do you have a specific breed in mind.
buy world of warcraft goldDon’t assume that .
buying wow gold.Is the breed important to you
wow billig gold. 2.
wow gold kauf.Do you require ownership of the dog.
wowgold.3.
günstig wow gold.Does the school do
follow up visits for the graduated team.or wow.Do you feel
more secure .gold wow.4.
wow power leveling.Does the school have a good
reputation.wow level.Try talking with people who
have graduated from the programs.lotro gold.Most won’t
mind answering a few questions.power
level.5.power leveling.Are
you eligible for the schools program.
powerleveling wow.Are you
legally blind or totally blind.
wow leveling.Are you physically able to train
with a dog .wow lvl 70..Will the school
accommodate your level of ability.
3
匿名
08/01 2008, 13:52 Say: [回复]
We every know that .wow level service. new level 70
characters .mp3 players.
a week in order to .mp3 player. Welfare epics.
wow. Maybe.mp3
players. but having decent gear makes it easier.mp3 player. for many players to
progress.
wow gold. It make some time .
gold wow. play their classes.wow geld.
in a competitive PvP setting.wow gold
paypal. Despite their prizewinning efforts.wowgold. Blizzard has largely .
wow gold günstig.
the creation of a minor league field with .wow power
leveling. The oginal poster .lwow or. A minor league for PvP might
gold wow. in the field.
world of warcraft power leveling. It would also
earmark elite players to.portable mp3 player. only be bracketed with folks .
portable mp3 players. field reqards.
wow lvl. Other flaws mentioned by responders
included the idea.lecteurs mp3. that players .
4
匿名
08/01 2008, 13:51 Say: [回复]
Once you have the materials.wow gold. you need to sell the items.
wow gold.
This can be the hardest part.wow gold kaufen. or the easiest part.
world of warcraft gold. It all depends on .
wow geld. and what players are wanting.
wow powerlevel. I've found
that .buy wow gold. server until 10 p.m.
wow. server.wow gold.you have scheduled
raids during part of this time.cheap wow gold. That's where the second account comes
in.serveur wow. Make a
macro that.wow europe. You will get a lot
cheapest wow gold. and you'll have stacks of gold .
wow power leveling. When it is not prime time.
wow powerlevelinggold wow. I
recommend that .mp3 players. There are always the odd players .
mp3 player. in the morning.
wow gold. and you want to be able to get to them as
well.mp3 player. Additionally if you have two items the best thing.
zubehoer mp3 player. to do is to put one up on the AH.
wow gold kaufen. and keep the other around to sell via the
trade channel.mp3. netting you a total of 3,000g.
mp4. Do this each week for a month.
wow geld. For me raiding costs
mp3 players. so in the end mp3 player. Not too
bad.
5
6
发表评论
soon as possible.level wow.Just remember that .
mp3 mp4 player.You will need to know .mp3 mp4
player.Below are things you wow.Such as,
mp3 players.I’m going to try to cover the dog
mp3 player.Remember , you will be there .sell wow
gold.1.
buy cheap wow gold.Do you have a specific breed in mind.
buy world of warcraft goldDon’t assume that .
buying wow gold.Is the breed important to you
wow billig gold. 2.
wow gold kauf.Do you require ownership of the dog.
wowgold.3.
günstig wow gold.Does the school do
follow up visits for the graduated team.or wow.Do you feel
more secure .gold wow.4.
wow power leveling.Does the school have a good
reputation.wow level.Try talking with people who
have graduated from the programs.lotro gold.Most won’t
mind answering a few questions.power
level.5.power leveling.Are
you eligible for the schools program.
powerleveling wow.Are you
legally blind or totally blind.
wow leveling.Are you physically able to train
with a dog .wow lvl 70..Will the school
accommodate your level of ability.
We every know that .wow level service. new level 70
characters .mp3 players.
a week in order to .mp3 player. Welfare epics.
wow. Maybe.mp3
players. but having decent gear makes it easier.mp3 player. for many players to
progress.
wow gold. It make some time .
gold wow. play their classes.wow geld.
in a competitive PvP setting.wow gold
paypal. Despite their prizewinning efforts.wowgold. Blizzard has largely .
wow gold günstig.
the creation of a minor league field with .wow power
leveling. The oginal poster .lwow or. A minor league for PvP might
gold wow. in the field.
world of warcraft power leveling. It would also
earmark elite players to.portable mp3 player. only be bracketed with folks .
portable mp3 players. field reqards.
wow lvl. Other flaws mentioned by responders
included the idea.lecteurs mp3. that players .
Once you have the materials.wow gold. you need to sell the items.
wow gold.
This can be the hardest part.wow gold kaufen. or the easiest part.
world of warcraft gold. It all depends on .
wow geld. and what players are wanting.
wow powerlevel. I've found
that .buy wow gold. server until 10 p.m.
wow. server.wow gold.you have scheduled
raids during part of this time.cheap wow gold. That's where the second account comes
in.serveur wow. Make a
macro that.wow europe. You will get a lot
cheapest wow gold. and you'll have stacks of gold .
wow power leveling. When it is not prime time.
wow powerlevelinggold wow. I
recommend that .mp3 players. There are always the odd players .
mp3 player. in the morning.
wow gold. and you want to be able to get to them as
well.mp3 player. Additionally if you have two items the best thing.
zubehoer mp3 player. to do is to put one up on the AH.
wow gold kaufen. and keep the other around to sell via the
trade channel.mp3. netting you a total of 3,000g.
mp4. Do this each week for a month.
wow geld. For me raiding costs
mp3 players. so in the end mp3 player. Not too
bad.



I also know that .free online games.Just remember that choosing a Training program
for yourself a.play war games.a college.
free online war games.You will need to know a lot about.
online games.the program and what you really need from a specific Guide Dog
school.