Answer the question
In order to leave comments, you need to log in
Why is it not possible to write a string type variable into a structure field?
Itm* CrItm(int Id, std::string Inf)
{
Itm *t = new Itm;
t->next = t->prev = NULL;
t->id = Id;
t.Info = Inf; // здесь ошибка
return t;
}
struct Itm {
int id;
std::string Info[Max_ch];
Itm *next, *prev;
};
Answer the question
In order to leave comments, you need to log in
Because the Info field is an array of strings, not a single string. Those. you are in fact trying to write the value of a variable of one type to a variable of another type. Suppose this code should already compile:
This means: assign the value of the variable Inf to the first element of the Info array. However, I'm not sure if that's what you want. Perhaps you just need to make the Info variable a regular string, not an array, and then your code will work too.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question