大哥大姐帮看下一C++错误

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:27:47
编写程序定义一个vector对象,其每个元素都是指向string类型的 指针,读取该vector对象,输出每个string的内容及其相应的长度。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
main()
{
string **a;
vector<string*> b;
vector<string*>::iterator c;
while(cin>>**a)
b.push_back(*a);
for(c=b.begin();c!=b.end();++c)
cout<<**c<<(**c).size()<<endl;
system("pause");
return 0;
}
同志门帮我看下,我编译没错,可运行就出现什么什么该内存不能为"read"的错误。。。

为什么老弄些多此一举的题,人都做傻了

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string a,*str = new string; //不能直接用指针作为输入
vector<string*> b;
vector<string*>::iterator c;
while(cin>> a) //*a的输入是错误的
{
*str = a;
b.push_back(str);
}
for(c=b.begin();c!=b.end();++c)
cout<<**c<<(**c).size()<<endl;
system("pause");
return 0;
}

string **a;声明后并没有初始化指向任务内存地址呀,肯定会不能为"read"了

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string **a;
vector<string*> b;
vector<string*>::iterator c;
while(cin>>**a)
b.push_back(*a);
for(c=b.begin();c!=b.end();++c)
cout<<**c<<(**c).size()<<endl;
system("pause&qu