elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Error "no match for operators"
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Error "no match for operators"  (Leído 2,345 veces)
MauriiOrtiz09

Desconectado Desconectado

Mensajes: 1


Ver Perfil
Error "no match for operators"
« en: 15 Febrero 2022, 22:45 pm »

No me deja ejecutar el programa por un error en la línea 189.
Alguien puede ayudarme?

Código
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. //----------------------- PROTOTIPO FUNCIONES --------------------------//
  9.  
  10. void menu();                                       // Muestra el menu principal
  11. void Agregar(struct Datos Persona[],int,int);     // Ingreso de contactos
  12.  
  13. // Funciones de Consulta
  14. void Consultar(struct Datos Persona[],int);          // Busqueda con menu
  15. void BuscaNombre(struct Datos Persona[],int);     // Buscar por Nombre
  16.  
  17. // Funciones para mostrar la info de los contactos
  18. void Listar(struct Datos Persona[],int);           // Muestra todos los contactos
  19. void ImprFicha(struct Datos Persona[],int,int);     // Imprime la informacion de los contactos
  20.  
  21.  
  22.  
  23. // Funcion Borrar
  24. void Borrar(struct Datos Persona[],int &ocup,int borrado);
  25.  
  26. //----------------------- ESTRUCTURAS ----------------------------------//
  27. struct Datos
  28. {
  29.    string Apellido;
  30.    string Nombre;
  31.    string Telefono;
  32. string Email;
  33. };
  34.  
  35.  
  36. //------------------------ FUNCION PRINCIPAL ----------------------------//
  37. main()
  38. {
  39.    const int MAX = 100;   // Cantidad de Contactos a guardar
  40.  
  41.    Datos Persona[MAX];  // Defino la variable Persona del tipo Datos (estructura)
  42.  
  43.    int index = 0;  // Variable para el Indice cada contacto
  44.    int opcion;     // Opcion Menu principal
  45.    bool salir;     // Variable Para salir del menu principal
  46.    int borrado;
  47.    int ocupado=-1;
  48.  
  49.    do
  50.    {
  51.     system("cls");
  52.  
  53.        menu();  // Llamada funcion menu();
  54.  
  55.        cout << "\n\t Elija la opcion: ";
  56.        cin >> opcion;
  57.        cin.ignore();
  58.  
  59.        switch (opcion)    // Menu principal
  60.        {
  61.            case 1:
  62.                    system("clear");
  63.                    Agregar(Persona,index,MAX); // Llamo funcion Ingresar();
  64.                    index++;
  65.                    break;
  66.            case 2:
  67.                    system("clear");
  68.                    Consultar(Persona,index);  // Llamo funcion Consultar();
  69.                    break;
  70.            case 3:
  71.                    system("clear");
  72.                    Borrar(Persona,index,ocupado);  // LLamo funcion Borrar();
  73.                    break;
  74.            case 4:
  75.             system("clear");
  76.                    Listar(Persona,index);  // LLamo funcion Listar();
  77.                    break;
  78.            case 5:
  79.                    salir = true;
  80.                    break;
  81.            default:
  82.                    system("clear");
  83.                    cout << "Ingrese Opcion valida\n\n";
  84.                    break;
  85.        }
  86.    }while(salir == false);
  87.  
  88.    return 0;
  89. }
  90.  
  91. //--------------------- FUNCIONES ---------------------------//
  92.  
  93. // Funcion menu
  94. void menu()
  95. {
  96.    cout << "\t ******* MENÚ PRINCIPAL ******* \n\n";
  97.  
  98.    cout << "\t 1) Agregar contacto" << endl;
  99.    cout << "\t 2) Consultar contacto" << endl;
  100.    cout << "\t 3) Borrar contacto" << endl;
  101. cout << "\t 4) Listar contactos" << endl;
  102.    cout << "\t 5) Salir" << endl;
  103. }
  104.  
  105. // Funcion agregar
  106.  
  107. void Agregar(struct Datos Persona[], int numero, int MAX)  // Paso como parametros la estructura,index y LEN
  108. {
  109.    if(numero < MAX)  // Comparo el numero de contactos con la cantidad que se pueden guardar
  110.    {
  111.        cout << "\t Igresar Datos Ficha: #" << numero << endl << endl;
  112.  
  113.        cout << " Apellido: ";
  114.        getline(cin,Persona[numero].Apellido);
  115.        cout << " Nombre: ";
  116.        getline(cin,Persona[numero].Nombre);
  117.        cout << " Telefono: ";
  118.        getline(cin,Persona[numero].Telefono);
  119.        cout << " Email: ";
  120.        getline(cin, Persona[numero].Email);
  121.        cout << endl << endl;
  122.    }
  123.    else
  124.        cout << "LLEGO AL LIMITE DE CONTACTOS PERMITIDOS" << endl << endl;
  125. }
  126.  
  127. // Funcion imprficha
  128. void ImprFicha(struct Datos Persona[], int x) // x ==> paso parametro iterador i  // Funcion Imprimir info
  129. {
  130.    cout << "\t Informacion ficha: #" << x << endl << endl;
  131.    cout << " Apellido: " << Persona[x].Apellido << endl;
  132.    cout << " Nombre: " << Persona[x].Nombre << endl;
  133.    cout << " Telefono: " << Persona[x].Telefono << endl;
  134.    cout << " Email: " << Persona[x].Email << endl;
  135. }
  136.  
  137. // Funcion listar
  138. void Listar(struct Datos Persona[], int numero)
  139. {
  140.    for(int i=0 ; i<numero ; i++)
  141.    {
  142.        ImprFicha(Persona,i);     // Llamada Funcion para imprimir la info
  143.    }
  144.    cin.get();        // Pausa
  145.    system("clear");  // Lipmpia
  146. }
  147.  
  148. // Funcion consultar
  149. void Consultar(struct Datos Persona[], int numero)
  150. {
  151.    cout << "\t Busqueda por nombre y apellido: \n\n";
  152.  
  153.    string nomb;
  154.    string apell;
  155.    cout << " Digite el apellido: ";
  156.    getline(cin,apell);
  157.    cout <<  endl;
  158.    cout << " Digite el nombre: ";
  159.    getline(cin,nomb);
  160.    cout <<  endl;
  161.  
  162.  
  163.    for(int i=0 ; i<numero ; i++)
  164.    {
  165.        if(nomb == Persona[i].Nombre && apell == Persona[i].Apellido)
  166.        {
  167.            ImprFicha(Persona,i);
  168.        }
  169.        else
  170.        {
  171.         cout<<"Ingrese datos validos"<<endl;
  172. }
  173.    }
  174.    cin.get();
  175.    system("clear");
  176. }
  177.  
  178. // Funcion borrar
  179. void Borrar(struct Datos Persona[], int &ocup, int borrado)
  180. { bool encontrado=false;
  181. int i=0;
  182. string tel;
  183. if(ocup>-1)
  184. {
  185. cout<<"Ingrese numero de telefono: ";
  186. getline(cin,tel);
  187. while(i<=ocup && !encontrado)
  188. {
  189. if (Persona[i].Telefono == borrado)
  190. encontrado=true;
  191. else
  192. i++;
  193. }
  194. if(encontrado)
  195. {
  196. while(i<ocup)
  197. {
  198.  
  199. Persona[i]=Persona[i+1];
  200. i++;
  201. }
  202. ocup--;
  203. cout<<"Borrado"<<endl;
  204. }
  205. else
  206. cout<<"Ingrese un numero de telofono existente.";
  207. }
  208. system("pause");
  209. }
  210.  


Output: [ERROR] no match for 'operator=='(operand types are 'std::string' ...)


En línea

Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.937


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: Error "no match for operators"
« Respuesta #1 en: 15 Febrero 2022, 23:25 pm »

Telefono es std::string y borrado es int.


En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines