Click here to Skip to main content
15,501,984 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionClist Find question Pin
ForNow29-Apr-22 4:12
MemberForNow29-Apr-22 4:12 
AnswerRe: Clist Find question Pin
Richard Andrew x6429-Apr-22 4:34
professionalRichard Andrew x6429-Apr-22 4:34 
GeneralRe: Clist Find question Pin
ForNow29-Apr-22 4:58
MemberForNow29-Apr-22 4:58 
GeneralRe: Clist Find question Pin
Richard Andrew x6429-Apr-22 5:02
professionalRichard Andrew x6429-Apr-22 5:02 
GeneralRe: Clist Find question Pin
ForNow29-Apr-22 5:15
MemberForNow29-Apr-22 5:15 
GeneralRe: Clist Find question Pin
Richard Andrew x6429-Apr-22 5:17
professionalRichard Andrew x6429-Apr-22 5:17 
Questionvector, adding things Pin
Calin Negru25-Apr-22 19:42
MemberCalin Negru25-Apr-22 19:42 
AnswerRe: vector, adding things Pin
CPallini25-Apr-22 21:21
mveCPallini25-Apr-22 21:21 
Actually, as its name suggestes, push_back adds an item at the back of the vector.
Try the following sample code in order to see insert in action:
C++
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  vector <int> v;

  v.push_back(1);
  v.push_back(2);
  v.push_back(3);

  cout << "v-front " << v.front() << "\n";
  cout << "v-back " << v.back() << "\n";

  v.insert(v.begin(), 4); // insert '4' before the first item: now '4' is the new front of 'v'

  cout << "v-front " << v.front() << "\n";

  v.insert(v.end() - 1, 5); // insert '5' just before the last item (back) of 'v', now '5' is the second-last item of 'v'

  v.insert(v.end(), 6); // insert '6' just before the 'pass-the-end' of 'v', that is '6' is the new back of 'v'.

  for (auto x : v) // show, in order, all 'v' items
    cout << x << " ";
  cout << "\n";
}

"In testa che avete, Signor di Ceprano?"
-- Rigoletto

GeneralRe: vector, adding things Pin
Calin Negru25-Apr-22 22:42
MemberCalin Negru25-Apr-22 22:42 
GeneralRe: vector, adding things Pin
CPallini25-Apr-22 22:43
mveCPallini25-Apr-22 22:43 
AnswerRe: vector, adding things Pin
Randor 26-Apr-22 17:03
professional Randor 26-Apr-22 17:03 
GeneralRe: vector, adding things Pin
Calin Negru27-Apr-22 0:09
MemberCalin Negru27-Apr-22 0:09 
QuestionWhy won't VS2015 let me compile? Pin
charlieg21-Apr-22 9:17
Membercharlieg21-Apr-22 9:17 
AnswerRe: Why won't VS2015 let me compile? Pin
Victor Nijegorodov21-Apr-22 10:14
MemberVictor Nijegorodov21-Apr-22 10:14 
GeneralRe: Why won't VS2015 let me compile? Pin
charlieg21-Apr-22 10:51
Membercharlieg21-Apr-22 10:51 
GeneralRe: Why won't VS2015 let me compile? Pin
Victor Nijegorodov21-Apr-22 11:25
MemberVictor Nijegorodov21-Apr-22 11:25 
GeneralMessage Closed Pin
25-Apr-22 21:44
professionalMasudul Herry25-Apr-22 21:44 
GeneralRe: Why won't VS2015 let me compile? Pin
Victor Nijegorodov26-Apr-22 2:54
MemberVictor Nijegorodov26-Apr-22 2:54 
GeneralRe: Why won't VS2015 let me compile? Pin
Richard Deeming26-Apr-22 3:41
mveRichard Deeming26-Apr-22 3:41 
GeneralRe: Why won't VS2015 let me compile? Pin
Richard MacCutchan26-Apr-22 3:41
mveRichard MacCutchan26-Apr-22 3:41 
AnswerRe: Why won't VS2015 let me compile? Pin
Greg Utas21-Apr-22 13:13
mveGreg Utas21-Apr-22 13:13 
GeneralRe: Why won't VS2015 let me compile? Pin
charlieg25-Apr-22 1:56
Membercharlieg25-Apr-22 1:56 
JokeRe: Why won't VS2015 let me compile? Pin
Randor 21-Apr-22 15:04
professional Randor 21-Apr-22 15:04 
GeneralRe: Why won't VS2015 let me compile? Pin
charlieg22-Apr-22 1:19
Membercharlieg22-Apr-22 1:19 
AnswerRe: Why won't VS2015 let me compile? Pin
charlieg22-Apr-22 1:29
Membercharlieg22-Apr-22 1:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.