#include <iostream>
#include <string>
using namespace std;
struct record {
	string	C0;
	string	C1;
	string	C2;
};
int main()
{
	record  param;
	param.C0 = "heading1";
	param.C1 = "heading2";
	param.C2 = "heading3";
	string key = "CO";
	string data = param.C0;
	cout << "DATA: " << data << endl; 
	return 1;
}

Is it possible to replace 'C0' with the variable 'key'?
ie:
string data = param.??key??; // where key is interpolated to 'C0'.

Like

#include <iostream>
#include <string>
using namespace std;
struct record {
	string	C[3];
};
int main()
{
	record  param;
	param.C[0] = "heading1";
	param.C[1] = "heading2";
	param.C[2] = "heading3";
	int key = 0;
	string data = param.C[key];
	cout << "DATA: " << data << endl; 
	return 0;  // zero is success
}

Or maybe

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
  map<string,string> param;
  param["C0"] = "heading1";
  param["C1"] = "heading2";
  param["C2"] = "heading3";
  string key = "C0";
  string data = param[key];
  cout << "DATA: " << data << endl;
  return 0;
}
This article has been dead for over six months. Start a new discussion instead.