#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
char* pwords[] = {"qa", "w","e","r"};//此处是字符串指针数组
char words[] = {'q','w','e'};
//char words[] = {"u","v","c"};//之前改写成这样发现输入项过多的错误,原来是误把字符串赋给了字符数组
cout << sizeof(pwords) << endl;//16,4个指针所占的空间大小
cout << sizeof(char) << endl;//1
cout << sizeof(char *) << endl;//4
cout << sizeof(words) << endl;//3,3个字符所占的空间大小
cout << sizeof(pwords) /sizeof(char *) <<endl;//4,算出在pwords中的元素个数
cout << *pwords[1] << endl;//w
size_t pwords_size = sizeof(pwords) /sizeof(char *);
list<string> pwords2(pwords, pwords + pwords_size);//用内置数组中的指针对容器初始化,其中第二个指针pwords_size提供停止复制的条件,其所指向的位子上存放的元素并没有复制
system("pause");
return 0;
}
C++ Primer Chapter 9 利用内置数组中一对指针初始化容器
最新推荐文章于 2022-02-11 13:34:06 发布