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 6992447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:38:08+00:00 2026-05-27T19:38:08+00:00

I couldn’t find this anywhere on the web so I’m most likely is not

  • 0

I couldn’t find this anywhere on the web so I’m most likely is not the correct way to tackle the issue, but maybe:

I got a class which have the values A and B, I store both of these in a collective vector. Is there a way to only get access to value A from within the vector? Or would I have to create separate vectors for the values?

Someone wanted to see part of my code, so here:

class Read{
    friend ostream &operator<<(ostream &,const Read &);
    public:
        Read(char,float,float,float);
        ~Read();
    private:
        char objekt_;
        float x_, y_, r_;
};

int main(){
    vector<Read> v_read;

    while(fin >> objekt >> x >> y >> r){
        v_read.push_back(Read(objekt, x, y, r));
    }

    return 0;
}

Out from that vector I would like to access my objekt_ values in each part of the vector.

  • 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-05-27T19:38:08+00:00Added an answer on May 27, 2026 at 7:38 pm

    Given a vector ofstructs with two things in the struct we can do things like:

    #include <vector>
    #include <algorithm>
    #include <boost/bind.hpp>
    #include <iterator>
    #include <iostream>
    
    struct test {
      int a;
      double b;
    };
    
    int main() {
      std::vector<test> vec = {{0, 0.1}, {1, 0.2}};
    
      // Copy the a's to another iterator
      std::transform(vec.begin(), vec.end(),
                     std::ostream_iterator<int>(std::cout, "\n"),
                     boost::bind(&test::a,_1));
    
      // and the b's to another iterator
      std::transform(vec.begin(), vec.end(),
                     std::ostream_iterator<double>(std::cout, "\n"),
                     boost::bind(&test::b,_1));
    
      // or just copy them into another vector
      std::vector<int> veca;
      veca.reserve(vec.size());
      std::transform(vec.begin(),vec.end(),
                     std::back_inserter(veca),
                     boost::bind(&test::a,_1));
    }
    

    To work with only part of each struct for all the entries in a given std::vector.

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

Sidebar

Related Questions

couldn't find a similar topic but this may boil down to not knowing how
Couldn't find this anywhere, maybe I'm looking for the wrong verbs. I'm trying to
I couldn't find an answer anywhere on the Web, so I'm going to answer
Couldn't find it anywhere (google or stackoverflow). Is there a way to force Dump()'s
Couldn't find an answer to this question. It must be obvious, but still. I
I couldn't find this anywhere, so i thought I'd ask here. Can you do
Couldn't really find it, but probably it's me not knowing how to search properly
Couldn't find any answer to this problem, or not even any questions asked. So
I couldn't find this in the docs , but how am I meant to
I couldn't find a suitable title for this. I'm going to express my query

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.