关于vector的有关问题,代码编译通过,运行出错~求教

关于vector的问题,代码编译通过,运行出错~求教…
代码实现的功能是想向vector容器中添加元素并输出~~
但是编译能通过,执行时输入元素后出现错误,各位高手帮忙看看…怎么回事。。。

但是也会提示错误, The variable 'spvec' is being used without being initialized.想问问spvec该怎么定义呢?

代码如下:

C/C++ code

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    //input
    vector<string> *spvec;
    string str;
    while(cin>>str)
        spvec->push_back(str);

  //output
    vector<string>::iterator iter=spvec->begin();
    while(iter!=(spvec->end()))
    {
        cout<<*iter<<""<<iter->size()<<endl;
        ++iter;
    }
    return 0;
}



------解决方案--------------------
vector<string> *spvec;
你的指针没有初始化
------解决方案--------------------
vector<string> *spvec = new vector<string>;
------解决方案--------------------
没必要用指针吧,要用记得new 和 delete
------解决方案--------------------
探讨
引用:

vector<string> *spvec = new vector<string>;


要是说用new动态分配了内存,对于这种vector容器该怎么释放内存呢?就是用delete怎么写?
刚学C++,不太明白…

------解决方案--------------------
这里根本没必要用指针- -!
vector<string> spvec
就好了。
反正你都用到了迭代器,一样是一个指针。
如果你要用指针就要动态分配内存