-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