#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;
}
箭头操作符
最新推荐文章于 2023-07-10 16:25:05 发布