#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'.

No.

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.