箭头操作符

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main ()
{
    vector<string*> spvec;

	string str;
	cout << "Enter some strings(Ctrl+Z to end)" << endl;
	while(cin >> str)
	{
         string *pstr = new string;
		 *pstr = str;
		 spvec.push_back(pstr);
	}

	cout << "现在开始输出:" << endl;
	vector<string*>::iterator iter = spvec.begin();
	while(iter != spvec.end())
	{
		cout << **iter << " " << (**iter).size() << endl;//一次*引用就是指针得到迭代器所指向的数据,两次**引用是得到的字符串,
	                            //(*iter)->size()
		++iter;
	}

	iter = spvec.begin();
	while(iter != spvec.end())
	{
         delete *iter;  //迭代器是一个指针,*iter是指针的指针,
		 ++iter;
	}

	return 0;
}

你可能感兴趣的:(箭头操作符)