yolocalhost: I am working on loading csv structure to array and I am getting this error Structures or classes containing objects are not allowed.
struct signals_data{ string order_id; ⋮ signals_data signals_arr[MC_MAX];
The default constructor has a special purpose when initializing an array of objects of its class
Structures, Classes and Interfaces - Data Types - Language Basics - MQL4 ReferenceWhy are those (except symbol) strings? You should change the types to actual values and adjust the read method (№ 3)
-
if(!FileReadStruct(export_file_handle, signals_arr[0])){
Your file is text. Read Struct only works with binary files; you have text. Read the manual! Add a read method to your struct, so it reads itself:void read(int H){ order_id = FileReadString(H); actual_date = FileReadDateTime(H); symbol = FileReadString(H); operation = FileReadString(H); price = FileReadNumber(H); ⋮
- yolocalhost: I was also trying to changeRead Array only works with binary files; you have text. Read the manual! Open the file, then while it is not ending, have the next array element read it: for(int i=0; !FileIsEnding(export_file_handle); ++i) signals_arr[i].read(export_file_handle);
FileReadStruc -> FileReadArray FileOpen(export_path, FILE_READ|FILE_CSV, ",")
- You are reading, what are you attempting to flush?
-
string order_id[MC_MAX]; datetime actual_date[MC_MAX]; string order_date[MC_MAX]; string symbol[MC_MAX]; string operation[MC_MAX]; double price[MC_MAX]; double tp_1[MC_MAX]; double tp_2[MC_MAX]; double tp_3[MC_MAX]; double sl[MC_MAX];
Drop unused declarations.
Thank you William, you are helpful.
Here is working code:
#define MC_MAX 15 struct signals_data{ string order_id; string order_date; string symbol; string operation; double price; double tp_1; double tp_2; double tp_3; double sl; //--- Default constructor signals_data() { order_id=""; order_date=""; symbol=""; operation=""; price=0.0; tp_1=0.0; tp_2=0.0; tp_3=0.0; sl=0.0; } //--- Read data void read(int handler){ order_id = FileReadString(handler); order_date = FileReadString(handler); symbol = FileReadString(handler); operation = FileReadString(handler); price = FileReadNumber(handler); tp_1 = FileReadNumber(handler); tp_2 = FileReadNumber(handler); tp_3 = FileReadNumber(handler); sl = FileReadNumber(handler); } }; void OnStart(){ //--- string export_path = "export.csv"; //--- signals_data signals_arr[MC_MAX]; //--- ResetLastError(); int export_file_handle = FileOpen(export_path, FILE_READ, ","); if(export_file_handle != INVALID_HANDLE){ for(int i=0; !FileIsEnding(export_file_handle); i++){ signals_arr[i].read(export_file_handle); } Print(signals_arr[0].order_id); Print(signals_arr[0].order_date); FileClose(export_file_handle); }else{ Print("File open failed, error ", GetLastError()); } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I am newbie here, so sorry if something wrong with this post.
I am working on loading csv structure to array and I am getting this error Structures or classes containing objects are not allowed.
I found https://www.mql5.com/en/forum/255091 but not helped me with this error.
CSV file consists this lines:
Code for reading to structure:
And after compile, the error is made.
I was also trying to change
But not helped me.
Thank you for your help.
Have a nice day.