Is it possible to reference (or point to) part of an array? Example:
Code:char name[]={'b','j','a','r','n','e','\0',};
char &jar=// 'j','a','r'
Printable View
Is it possible to reference (or point to) part of an array? Example:
Code:char name[]={'b','j','a','r','n','e','\0',};
char &jar=// 'j','a','r'
char* jar = &name[1];
now a cout << jar << endl; would print "jarne"
Is there a way to terminate it at 'r' (i.e. "jar")?Quote:
Originally Posted by Perspective
if you dont mind ruining the original string you can set the next char to '\0' (ie: name[4] = '\0';) otherwise you'll have to copy the part you want into a different memory location.
No, I didn't want to touch the original string. Thanks for your help.Quote:
Originally Posted by Perspective
You could write a "substring" class that does that.
Do you know ahead of time how much of the string you will need or is that a runtime decision?