I have a char array which is VERY large and I iterate through the array. I look for patterns with logic such as:
if (array[n] == 'x' and array[n+1] == 'y' and array[n+2] == 'z')
{
mystring = array[n+4] + array[n+5];
}
if array[n+4] is '4' and array[n+5] is '5' then mystring = "45"
However, mystring is always "", what am I doing wrong? I don't want to use substring as the array is too large. I just want to cast the chars to strings and then append to mystring.
myString = std::string(array[n + 4]) + array[n + 5]for an even shorter variant.std::string mystring = std::string(1,array[i + 4]) + array[i + 5];as none of the constructor takes justchararray[n+4] + array[n+5]doesn't do what you think it does. It takes the two characters as ASCII values and adds them together to create a new single character. It doesn't create a new string with the two characters concatenated.