显示向量的内容,其中显示for循环一值

displaying the contents of a vector with a for loop one value displayed

本文关键字:显示 for 循环 向量      更新时间:2023-10-16

嗨,这个程序有点问题。for循环的结果只显示一个值,程序中的delete函数不起作用。我很难用不同的方式来思考这个问题。

   // dvd title library

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int adqv, ete, ti;
vector<string> dvdtitle(101);
vector<string>::const_iterator place;
string title, second, third ;

do{cout<< "welcome to your Dvd library!"
&& cout<< "     To add titles enter 1.                              To                        delete titles enter 2.            Type 3 to quit"
 && cin>>adqv;

switch (adqv)
{case 1 : cout<<"Enter the title name"
&& cin >>title
&& cout<<"Enter another title"
&& cin>>second
&& cout <<"Enter a third title"
&&cin>>third;
   break;
case 2: 
cout<<"enter the number of the title to be deleted. starting with 0  then     1"
 && cin>>ete;
break;
case 3:
    {return 0;}
default: cout<<"invalid choice";}
dvdtitle.push_back(title);
dvdtitle.push_back(second);
dvdtitle.push_back(third);
 if (adqv=2)
 dvdtitle.erase(dvdtitle.begin()+ete);
sort(dvdtitle.begin(), dvdtitle.end());
  for ( place = dvdtitle.begin(); place< dvdtitle.end()  ; ++place);
  { cout<< "             These are your titles           ";
  cout<< *place;

  }

}while (adqv !=3);
}

线路for ( place = dvdtitle.begin(); place< dvdtitle.end() ; ++place);

不应包含分号";"最后。它充当循环的一个空体,当循环结束时,place将等于dvdtitle.end(),一个超过结束迭代器的值,当您稍后尝试打印它时,您超出了向量的范围。