For future questions, please correctly explain the problem. We are not fortune tellers, so if you pose the problem in such a way that it is easy to understand your question, you will receive more answers and solutions.
This is important because, as you will see below, your program is a factory of both code and conceptual errors and in cases like this, it is possible that the person who answers you will forget about the problem that prevents you from working.
So you know, if you want quality answers, ask yourself a quality question.
In C ++ fixed-size arrays ( char array[10]
) can not be copied with the assignment operator because they do not have a valid overhead.
Since you are already using std::string
in your program I suggest you replace the type of cedula
so that it is also a std::string
:
struct nodo{
int nro;
string nombre;
string cedula; // <<---
string apellido;
struct nodo *sgte;
};
void insertarInicio(Tlista &lista, int valor, string dato, string _cedula, string _apellido)
// ~~~~~~
{
Tlista q;
q = new(struct nodo);
q->nro = valor;
q->nombre = dato;
q->cedula = _cedula; // <<---
q->apellido = _apellido;
q->sgte = lista;
lista = q;
}
But here the thing does not end. C ++ is not C . C ++ is an object-oriented language, so it is not necessary to use struct
everywhere:
struct nodo{
int nro;
string nombre;
string cedula;
string apellido;
struct nodo *sgte;
// ~~~~~~ Esto sobra
};
typedef struct nodo *Tlista; // <<--- Y esto también
void insertarInicio(nodo *& lista, ...) // No hace falta usar struct
In addition, the new
operator can be used more intuitively:
nodo* q = new nodo;
And, to finish, note that your program is not able to exit the loop using option 3:
case 3:
system("cls");
break;
That break
serves to exit switch
, but you would need a second break
to exit the do-while
loop. How can you not nest the loops:
case 3:
system("cls");
break;
break; // Este break no se ejecutaría nunca
The option is to correctly configure the condition of the do-while
loop:
do
{
// ..
} while(op!=3); // 3, no 8!!!!
And, by the way, although you still do not use it, the function insertarElemento
is not going to work as expected ... this function is able to insert up to 4 elements in a single stroke (counts the number of times that% appears new
in that function).