Hello,

I am not sure how can I make a string / char array that can behave like the Asset variable.

I have this structure to store the last X prices of all the timeframes of all the assets in the global namespace:
Code
map<char*, map<int, deque<double>>> prices;

(FYI std::deque is like std::vector, but it is optimized for pushing elements also to the front.)
So I can store all the prices like this:
Code
TimeFrame = 5;
if (frame(0)){
   prices[Asset][TimeFrame].push_front(priceClose(0));
   // ... maintain the length of the deque
}


Filling up with data is done. But when I want to read it I have a problem.

I have 3 assets, and in the asset loop there is this sequence:
Code
for (pair<char*, map<int, deque<double>>> element: prices){
   printf("\n -- %s", element.first);
}

Result:
Code
 -- USDJPY
 -- EURUSD
 -- XAUUSD


The following code is also ok, prints the last price of the current asset:
Code
printf("%s--- %.5f", Asset, prices[Asset][5][0]);


But this two following goes into runtime crash:

Code
//v1 crash
printf("%s--- %.5f", "EURUSD", prices["EURUSD"][5][0]);

//v2 crash
char* asd = "EURUSD";
printf("%s--- %.5f", asd, prices[asd][5][0]);


I got the runtime crash because these deques haven't got element 0.
This code...:
Code
printf("\n--- size Asset: %d, size EURUSD: %d", prices[Asset][5].size(), prices["EURUSD"][5].size());
printf("\n diff: %d", strcmp(Asset, "EURUSD"));
...prints the following:
Code
---size Asset: 800, size EURUSD: 0
 diff: 0

So my question is, what is the difference between Asset / char* var / string literal? The content of Asset is "EURUSD", and comparing to literal "EURUSD" returns 0, but anyways they are different somehow. How can I make a variable or literal "act like" an Asset, to use that prices map I described before?

Last edited by NorbertSz; 09/18/22 12:52.