Ejemplo de un programa en C++ donde se manipulan archivos de datos Prof. Carlos A. Rodríguez Sánchez
salida << setprecision(2); salida << fixed << showpoint; salida << setprecision(2); cout << "Procesando los datos:" << endl; while (!entrada.eof()) { entrada >> firstName >> lastName; salida << "Student Name: " << firstName << " " << lastName << endl; entrada >> test1 >> test2 >> test3 >> test4 >> test5; salida << "Test Scores: " << setw(6) << test1 << setw(6) << test2 << setw(6) << test3 << setw(6) << test4 << setw(6) << test5 << endl; average = (test1 + test2 + test3 + test4 + test5 ) / 5.0; salida << "Average test score: " << setw(6) << average << endl; } entrada.close(); salida.close(); cout << "Fin del procesamiento de archivos..." << endl; system("pause"); return 0; // EJEMPLO DE UN PROGRAMA QUE PROCESA ARCHIVOS DE DATOS // EN C++ #include<iostream> #include<fstream> #include<iomanip> #include<string> using namespace std; int main() { ifstream entrada; ofstream salida; double test1, test2, test3, test4, test5; double average; string firstName; string lastName; entrada.open("est.txt"); salida.open("promedios.out");
Archivo de Datos de entrada Andrew Miller 87.5 89 65.75 37 98.5 John Doe 90 77 83 92 90 Jane Doe 99 56 72 72 81 Archivo de Salida Student Name: Andrew Miller Test Scores: 87.50 89.00 65.75 37.00 98.50 Average test score: 75.55 Student Name: John Doe Test Scores: 90.00 77.00 83.00 92.00 90.00 Average test score: 86.40 Student Name: Jane Doe Test Scores: 99.00 56.00 72.00 72.00 81.00 Average test score: 76.00
NotePad
Archivos