nr1= newstruct system[integer_nr];
for(int i=0;!file.eof();i++)
{
getline(file,data,';');
if(i<((*start_line*4)-4)||i>(*end_line*4)-1) continue;
//Now because I reached the line that I look for in the file i want to get the string parts and put them in the structure,but how can I do this??
// I have tried like this, with no success:
nr1[i].datum=data;
nr1[i].energie=data;
nr1[i].max=data;
nr1[i].min=data;
// All this variables get the same data
//I want to loop through all the variables and put in them the part strings I get from the file, like this:
first part string is: 26.08.2011 that should be saved in the variable nr1[i].datum than next part string 00000123 that should be saved in the next variable of the structure nr1[i].energie=data and so on
j++;
}
delete[]anlage;
file.close();
Can you help me with an advice or piece of code?
Note that I have to use dynamic arrays!
No the delimiter is the semicolon. When I use the getline function i can parse the string to part strings. But my problem is that I can not put this part strings into the variables of the structure.
I hope you have a solution for me.
Yes this is true. I have to convert the string into numbers and than to put them into the struct.
Can you tell me what king of loop I should use to put this data into the struct?
Sorry about my english, probably this is why you can not understand what I have to do.
I know that this should be very simple but I have no idea how to do it.
How can I put this part strings into the struct using loops or something else?
Please help!
structure system // should be struct and 'system' is not a great name because it clashes with a standard function
{
string datum;
// one of these is not an int in the file..? I guess energie
int energie; // should be double?
int max;
int min;
}nr1; // no reason to define an instance here
So this is probably better:
1 2 3 4 5 6 7 8 9
struct system_t // change name
{
std::string datum;
// rearranged to match the order in the file (I assume)
int min;
double energie; // now a double
int max;
};
For reading the datum I would use std::getline(file, sys.datum, ';');, however the other values, being numeric can be read using operator >> like file >> sys.energie;. You can skip the semicolons using: file.ignore();
yes you are right! there should be struct and not structure.
And double is much better! I only have to manage to put the data into the struct!
If i have a problem I will write here.
Thank you so much for helping me!
Can you tell me how can iterate through the variables in the struct and save there my data?
I have a dynamic array struct and I need to use loops.
Thank you