-2
我正在开发一个简单的基于控制台的电子邮件应用程序。如何从矢量中删除元素?
在我的应用程序中,邮件存储在std::vector
中,我想添加删除邮件的可能性。
如何从矢量中删除元素?
这里是我的代码:
//MAIN MENU OPTION 1 SELECTED:
// print list of all messages to the console
void viewInbox() {
vector<Message> inbox{
Message("[email protected]", "Knife you tonight", "Hey Sam, what kind of suit do you wanna be buried in?!"),
Message("[email protected]", "Urgent from paypal.com", "Dear paypal user, someone has hacked your account. Give us your password now so we change it!"),
};
cout << "You have " << inbox.size() << " new messages.\n";
cout << "Index Subject" << '\n';
for (int i = 0; i < inbox.size(); ++i)
std::cout << "Message " << i << ": " << inbox[i].getSubject() << '\n';
cout << "Please enter number of message you would like to view\n";
int read;
cin >> read;
cout << "From: " << inbox[read].getAddress() << '\n';
cout << "Subject: " << inbox[read].getSubject() << '\n';
cout << inbox[read].getMessageText() << '\n';
cout << "To erase this message press 1\n";
//Code here for deleting a message...
}//end of viewInbox()
改为使用'\ r',只是在它上面打印空格。 – 2014-10-04 23:21:29
Hans Passant,不是我要找的。如果用户输入1作为选项,我还需要从矢量中删除消息对象。 – 2014-10-04 23:39:22
@SamJava_The_Hut你的问题的标题很混乱,它表明你想从控制台删除一些东西,我要编辑它。 – GingerPlusPlus 2014-10-05 10:38:17