Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/11/2011, 06:59
josemiclfa
 
Fecha de Ingreso: agosto-2011
Mensajes: 7
Antigüedad: 12 años, 8 meses
Puntos: 0
Exclamación Error de compilación

Hola a todos, resulta que me da un error al compilar mi programa... dicho error es este:

conversion from `programa'to non-scalar type `std::string' requested


Os copio también la línea de código: (El error da en la línea 106, en el Lee(nuevo)

Código c++:
Ver original
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. struct programa {
  9.     string nombre;
  10.     int fecha;
  11.     int c;
  12. };
  13.  
  14. void Escribe (const programa &datos){
  15.     cout<<"Introduce nombre: "<<flush;
  16.     cout<<datos.nombre<<endl;
  17.     cout<<"Introduce fecha del día trabajado: "<<flush;
  18.     cout<<datos.fecha<<endl;
  19.     cout<<"Introduce un 1: "<<endl;
  20. }
  21.  
  22. void Escribe (const programa lis[], int tam){
  23.     for (int i=0; i<tam; i++){
  24.         cout<<"Días trabajados por la persona: "<<i+1<<endl;
  25.         Escribe (lis[i]);
  26.     }
  27. }
  28.  
  29. void Escribe (string nombreFich, const programa &datos){
  30.     ofstream salida (nombreFich.c_str(),ios::app);
  31.     if (salida) {
  32.         salida<<datos.nombre<<endl;
  33.         salida<<datos.fecha<<endl;
  34.         salida.close();
  35.     }
  36.     else cout<<"Error al abrir el archivo"<<nombreFich<<endl;
  37. }
  38.  
  39. bool Lee (string nombreFich, programa datos[],int &tam){
  40.     ifstream entrada;
  41.     entrada.open(nombreFich.c_str());
  42.     if (entrada){
  43.         int i=0;
  44.         while (getline(entrada>>ws,datos[i].nombre)){
  45.             entrada>>datos[i].fecha;
  46.             entrada>>datos[i].c;
  47.             i++;
  48.         }
  49.         tam=i;
  50.         entrada.close();
  51.         return true;
  52.     }
  53.     else cout<<"Error al abrir el fichero"<<nombreFich<<endl;
  54.     return false;
  55. }
  56. int Busca (const programa lis[], int tam, string name){
  57.     int i=0;
  58.     bool esta=false;
  59.     while (i<tam && !esta){
  60.         if(name==lis[i].nombre)
  61.             esta=true;
  62.         else i++;
  63.     }
  64.     if(esta)
  65.         return i;
  66.     else return -1;
  67.  
  68.  
  69. }
  70.  
  71. int ControlEnteros(int limi, int limis, string mensaje){
  72.     int valor;
  73.  
  74.     do{
  75.         cout<<mensaje<<" (valor entre "<<limi<<" y "<<limis<<" : "<<flush;
  76.         cin>>valor;
  77.  
  78.     }while(valor<limi || valor>limis);
  79.  
  80.     return valor;
  81. }
  82.  
  83. int Menu(){
  84.     int dato;
  85.     cout<<"1. Insertar día de trabajo"<<endl;
  86.     cout<<"2. Listar datos de trabajo"<<endl;
  87.     cout<<"3. Mostrar datos de persona"<<endl;
  88.     cout<<"4. Terminar"<<endl;
  89.  
  90.     dato=ControlEnteros(1,4,"Opción");
  91.  
  92.     return dato;
  93. }
  94.  
  95. int main(){
  96.     const int MAX=100;
  97.     programa lista[MAX],nuevo;
  98.     int opcion, t,pos;
  99.     string nombre;
  100.  
  101.  
  102.     do{
  103.         opcion=Menu();
  104.         switch(opcion){
  105.         case 1:{
  106.             Lee(nuevo);
  107.             Escribe("Trabajo.txt",nuevo);
  108.             break;
  109.         }
  110.         case 2:{
  111.             if (Lee("Trabajo.txt",lista,t))
  112.                 Escribe(lista,t);
  113.             break;
  114.         }
  115.         case 3:{
  116.             if (Lee ("Trabajo.txt",lista,t)){
  117.                 cout<<"Nombre de la persona a buscar: "<<flush;
  118.                 getline(cin>>ws,nombre);
  119.                 pos=Busca(lista,t,nombre);
  120.                 if (pos!=-1)
  121.                     Escribe(lista[pos]);
  122.                 else cout<<"Esa persona no está"<<endl;
  123.  
  124.             }
  125.             break;
  126.         }
  127.         }
  128.         cout<<endl<<endl;
  129.     }while(opcion!=4);
  130.     system("pause");
  131. }