Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/11/2008, 14:04
Avatar de Fayca
Fayca
 
Fecha de Ingreso: abril-2008
Mensajes: 164
Antigüedad: 16 años, 1 mes
Puntos: 2
Respuesta: Ayuda ofstream C++

el error que te lanza el compilador li dise TODO
declaration of 'std::ofstream guardar' shadows a parameter : declaracion de std::ofstream guardar oscurese un parametro,
buelbes a declarar la variable dentro de la funcion cuando ya la tienes en los parametros, ytambien esta mal puesto el prototipo y la declaracion de la funcion, tienes de prototipo:void guardamat(int[10][10]);
y la decalaración es esta
void guardamat (int matriz[10][10], ofstream& guardar)
como bes al prototipo le falta el parametro ofstream&
deberia de quedar asi:
Código:
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include<fstream>
using namespace std;

void creamat(int[10][10]);
void muestramat(int[10][10]);
void guardamat(int[10][10], ofstream&);

int main()
{
    ofstream guardar;

    int mat[10][10];

    creamat(mat);
    muestramat(mat);
    guardamat(mat, guardar);

    system("PAUSE");

    return 0;
}
void creamat(int matriz[10][10])
{
    int i, j;

    srand(time(NULL));

    for (i=0;i<10;i++)
    {
        for (j=0;j<10;j++)
        {
            matriz[i][j]=0+rand()%(10+1-0);
        }
    }
    return;
}
void muestramat(int matriz[10][10])
{
    int i, j;

    for (i=0;i<10;i++)
    {
        for (j=0;j<10;j++)
        {
            cout<<matriz[i][j];
        }
        cout<<endl;
    }
    return;
}
void guardamat (int matriz[10][10], ofstream& guardar)
{
    int i, j;
    //ofstream guardar;//aca marca el error
    char nombre[25];

    cout<<"Ingrese un nombre para el archivo donde guardará la matriz: ";
    cin.getline(nombre,25,'\n');
    guardar.open(nombre);


    for (i=0;i<10;i++)
    {
        for (j=0;j<10;j++)
        {
            guardar<<matriz[i][j];
        }
        guardar<<endl;
    }
    return;
}