Los archivos de escritura son los
ofstream , tenes que declarar una variable de ese tipo, por ejemplo:
Código:
ofstream ArchiSal("salida.txt");
un ejemplo con escribiendo bastantes boludeces
Código:
ofstream ArchiSal("salida.txt");
string Texto1 = "Hola";
string Texto2 = "Mundo";
int num = 1;
Archi << Texto1 << Texto2 << endl;
Archi << Texto1 << " " << Texto2 << endl;
Archi << num << num++ << endl;
Archi << num << " " << num++ << endl;
Archi << num++ << " " << num << endl;
Archi << Texto1 << num << "\n";
Archi << num++ << Texto2 << endl;
Al final, podes llamar al método close() si queres, igualmente este se llama al destruir la varaible
Para lectura
ifstream .
Código:
float PromedioDatos()
{
float x, suma = 0;
int cont = 0;
ifstream Archivo(“Datos.txt”);
while (!Archivo.eof())
{
Archivo >> x;
suma += x;
cont++;
}
return suma/cont;
}
Espero que te sirva para empesar