显示向量的内容,其中显示for循环一值
displaying the contents of a vector with a for loop one value displayed
嗨,这个程序有点问题。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()
,一个超过结束迭代器的值,当您稍后尝试打印它时,您超出了向量的范围。
相关文章:
- 为什么这个 for 循环总是显示"o"。C++
- 螺旋矩阵在最后一个"for"循环中中断,不显示任何内容
- 如何在 for 循环中显示一个结果
- 我的程序显示许多错误,"error: no matching function for call to 'getPercentScore'"
- 在 for 循环中仅显示序列的最后一个结果
- 如何在 for 循环中解决潜在的 getline() 问题,数组的第一个索引没有显示?
- 尝试将文件读入结构数组,但 for 循环仅显示第一个索引,其余索引显示为零
- 将 5 个 for 循环压缩为,将数组显示为 1
- 为什么编译器显示错误"no match for 'operator[]' (operand types are 'carti' and 'int')"
- 使用 "For Loop" 按以下顺序显示数字
- 当从此到子类中的新对象时,将显示警告"destination for this 'memcpy' call is a pointer to dynamic class..."
- 在 for 循环中显示索引图像
- 用于显示字符串每个字符的 for 循环 |C++
- 需要有关使用 for 循环显示我的数组的帮助
- 如何在 SysntasticCheck for vim 中显示所有" g++ -Wall "错误警告?
- 显示向量的内容,其中显示for循环一值
- 使用For循环显示1个结果
- 在一个for循环中显示2个迭代数组
- Xcode 调试不显示 for- 或 while-loops
- 无法显示 for 循环后的最后一个数字