こんにちは私はこのプログラムでいくつかの問題を抱えています。 forループの結果として1つの値しか表示されず、プログラムのdelete関数が機能しません。私はこれを別のやり方で考えていくのが難しいです。forループの1つの値を持つベクトルの内容を表示
// 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);
}
_「問題があります」_はかなり曖昧なエラーの説明です。投稿[MCVE]してください。 –
そのフォーマットで何を期待しましたか?それはあなたのチャンスを維持しています。 – LogicStuff
*ベクトル dvdtitle(101); *はベクトルに101個の要素を作成し、* dvdtitle.push_back(title); *は102要素というように追加し、次に* dvdtitle.erase(dvdtitle.begin ()+ ete); *あなたが考えると思われる要素は消去されません。 –