Skip to content

Instantly share code, notes, and snippets.

@notjames
Created June 19, 2018 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notjames/feb040ddcd1b9347dcb7ee1afc65b860 to your computer and use it in GitHub Desktop.
Save notjames/feb040ddcd1b9347dcb7ee1afc65b860 to your computer and use it in GitHub Desktop.
how to create a pointer array of strings where each element points to another element in const array
#include <string>
using namespace std;
const string data[] = {
"A1,string1",
"A2,string2",
"A3,string3",
"A4,string4",
"A5,string5",
"A6,string6",
"A7,string7",
"A8,string8",
};
int parse_data()
{
int num_elements = 0;
for ( unsigned int i = 0; data[i].length(); i++ ) num_elements++;
string *ptrarray[num_elements];
for ( int i = 0; i < num_elements; i++ )
{
ptrarray[i] = &data[i];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment