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

The Archive Base Latest Questions

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

I have a function that I set custom key and value to it and

  • 0

I have a function that I set custom key and value to it and I would like to return them to a receiver so they can see, I want to be able to see the key and the value so I can do something with it, like in this example I print them.

The example I put down there it’s pretty clear what I want.

//#functions.cpp

something returnKeyAndValue(){
     something valor;
     valor.login = "hey";
     valor.senha = "you";
     return valor;
}

something returnKeyAndValue2(){
     something valor;
     valor.value2 = "hello";
     valor.value1 = "string";
     return valor;
}

//... And a lot of other returnKeyAndValue functions

something PrintKeyAndValuesOfBoth(something KeyAndValue){

    for(int i = 0; i < KeyAndValue.size(); i++){
       string key = KeyAndValue[i].key;
       string value = KeyAndValue[i].value;

       cout << "Key: " << key << ", Val: " << value << endl;
    }

}

//#test.cpp

#import "functions.cpp"

int main () {

    something return = returnKeyAndValue();
    something return2 = returnKeyAndValue2();

     PrintKeyAndValuesOfBoth(return);
     PrintKeyAndValuesOfBoth(return2);

}

What could be this "something" type to do that something like it, how would I get the key and value of it.

I hope I was clear enough.
Thanks in advance.

@Edit – Solution

Idea of using map provided by Dvir Volk, based on his suggestion I made this example to show how to use it.

#include <iostream>
#include <string>
#include <map>

int main () {

    std::map< std::string, std::string > MyMap;
    std::map< std::string, std::string >::iterator MyIterMap; 

       MyMap["Teste1"] = "map1";
       MyMap["Teste2"] = "map2";
       MyMap["Teste3"] = "map3";
       
   MyIterMap = MyMap.begin(); 

   while(MyIterMap != MyMap.end() ) {
       std::string key = (*MyIterMap).first; 

       std::cout << "Key: " << key << ", Value: " << MyMap[key] <<std::endl;
       MyIterMap++;
   }
   std::cin.get();
   return 0;

}

Hope I helped.

  • 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:23:28+00:00Added an answer on May 31, 2026 at 11:23 pm

    You need std::map or std::unordered_map.
    You’ll need to implement hashing or comparison function (for map) to use a custom key and not a primitive type.

    You can of course create a vector of pairs, but then it will not be a key and value.

    see here: http://en.cppreference.com/w/cpp/container/map

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

Sidebar

Related Questions

I have a set of functions that I declare in a header like this:
I have a Unix bash function that executes a script that parses custom environment
I have an Excel workbook with a custom non-time-dependent cell function that I am
I have a set of custom PHP scripts. They load a main PHP file
I have a custom UserControl with a function that updates the AutoScrollMinSize each time
I have certain initializing functions that I use to set up audit logging on
I have a problem with a javascript set of functions that I made. This
I have a set of five functions, that could be called one of five
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in

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.