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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:42:19+00:00 2026-05-31T23:42:19+00:00

std::vector<std::pair<std::string > > can be used to store a list of a pair of

  • 0
std::vector<std::pair<std::string > >

can be used to store a list of a pair of strings. Is there a similar way to store a list of triplets of strings?

One way I can think of is to use std::vector

std::vector<std::vector<std::string > > v (4, std::vector<std::string> (3));

but this will not allow me to use the handly first and second accessors.

So, I wrote my own class

#include <iostream>
#include <vector>
using namespace std;

template <class T>
class triad {
private:
    T* one;
    T* two;
    T* three;
public:
    triad() {  one = two = three =0;  }
    triad(triad& t) {
        one = new T(t.get1());
        two = new T(t.get2());
        three = new T(t.get3());
    }
    ~triad() {
        delete one;
        delete two;
        delete three;
        one = 0;
        two = 0;
        three = 0;
    }
    T& get1() { return *one; }
    T& get2() { return *two; }
    T& get3() { return *three; }
};

int main() {
    std::vector< triad<std::string> > v;
}

I have two questions

  1. Can my class code be improved in any way?
  2. Is there any better way to do store triplets of strings than the three ways described above?
  • 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-31T23:42:20+00:00Added an answer on May 31, 2026 at 11:42 pm

    std::tuple is a generalization of std::pair that lets you store a collection of some size that you specify. So, you can say:

    typedef std::tuple<std::string, std::string, std::string> Triad;
    

    to get a type Triad that stores three strings.

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

Sidebar

Related Questions

It seems that I can sort a std::vector<std::pair<int, std::string>> , and it will sort
How can I sort this vector by comparing the pair.first which is an std::string
I have a std::vector<std::pair<int,std::pair<Bone,std::string> > > I'm trying to sort it with std sort,
I have a std::vector with the element as pair and need to find all
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
#include <boost/regex.hpp> #include <string> #include <iostream> using namespace boost; static const regex regexp( std::vector<
#include <boost/regex.hpp> #include <string> #include <iostream> using namespace boost; static const regex regexp( std::vector<
I have this map<string, vector <pair<int, int> > > variable and I'm pushing back
I have an std:map defined as follows: std:map<std::string country, std::vector<SomeClass> events>; Holds some events
Question Synopsis Given a std::vector<T> , how can I create a view that exposes

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.