Created
June 19, 2018 23:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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