Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:54:31+00:00 2026-06-17T03:54:31+00:00

I have a vector vec of structures. Such a structure has elements int a,

  • 0

I have a vector vec of structures. Such a structure has elements int a, int b, int c. I would like to assign to some int var the element c, from the last structure in a vector. Please can you provide me with this simple solution? I’m going circle in line like this:

var = vec.end().c;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:54:32+00:00Added an answer on June 17, 2026 at 3:54 am

    The immediate answer to your question as to fetching access to the last element in a vector can be accomplished using the back() member. Such as:

    int var = vec.back().c;
    

    Note: If there is a possibility your vector is empty, such a call to back() causes undefined behavior. In such cases you can check your vector’s empty-state prior to using back() by using the empty() member:

    if (!vec.empty())
       var = vec.back().c;
    

    Likely one of these two methods will be applicable for your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::vector. I assign this vector like vec.assign(20000, 0); Now I have
I have something like this that is incorect: vector<boost::thread> vec; for(int agent = 1;
I have a vector of pairs representing hops between nodes which I would like
Say I have a std::vector called vec with 10 elements and I want to
My class has a pointer vector: ptr_vector<Class> vec; And in some setup method adds
I have a vector of maps, which looks like this: (def game-vec [{:game 1
I have a vector with elements of type class A . Class A has
If I have a vector of pairs: std::vector<std::pair<int, int> > vec; Is there and
I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized
I have a vector where I keep an incrementing data. Normally each element of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.