首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ string类的有关问题

2013-12-15 
C++ string类的问题今天看书时碰到string类,于是想搞清楚它具体有哪些构造函数,看了一下有17个,其中有些用

C++ string类的问题
今天看书时碰到string类,于是想搞清楚它具体有哪些构造函数,看了一下有17个,其中有些用过了知道是什么意思了,还有些没用过想看看各个参数都是什么,没看懂,特别是用到typedef别名时,更是不懂了,比如

typedef typename _Alloc::template rebind<_Elem>::other _Alty;
这个具体是什么意思,谁替代谁啊,哪里有比较全的typedef的文档说明,和string类的文档说明,大家都是这么学习string类的?
[解决办法]
引用:
Quote: 引用:

#include <iostream>
#include <string>
typedef  std::string temp ; //temp就代表了string类型
int main()
{
temp show("example") ;//等于 string show ("example") ;
std::cout << show ;
}

像我这么长的替换中间不止两个空格的 ,两个空格的话是这样的 typedef  A   B  ;用B替换A
我这种情况,怎么分清楚那个是A 那个是B呢?
前者被后者替换

引用:
typedef  A   B  ;
意思就是用B 替代A


引用:
Quote: 引用:

#include <iostream>
#include <string>
typedef  std::string temp ; //temp就代表了string类型
int main()
{
temp show("example") ;//等于 string show ("example") ;
std::cout << show ;
}

像我这么长的替换中间不止两个空格的 ,两个空格的话是这样的 typedef  A   B  ;用B替换A
我这种情况,怎么分清楚那个是A 那个是B呢?


引用:
#include <iostream>
#include <string>
typedef  std::string temp ; //temp就代表了string类型
int main()
{
temp show("example") ;//等于 string show ("example") ;
std::cout << show ;
}
typedef  A   B A是一个变量类型 比如 int string unsigned当然也可以是一个指针
[解决办法]
引用:
Quote: 引用:

http://www.cplusplus.com/reference/string/string/
这个是C++标准库的文档。

看到这样一个构造函数
string (string&& str) noexcept;

move constructorAcquires the contents of str.
str is left in an unspecified but valid state. 什么意思呢?

这是移动构造函数,是C++11的新特性。它定义了对象的浅拷贝操作,用于减少不必要的深拷贝。
在这个函数里,你可以自己定义浅拷贝的操作。编译器会在自己认为合适的时候,仅对对象进行浅拷贝。
这个东西我不是很熟悉,因为我没用过C++11。

热点排行