add solution of lab01

This commit is contained in:
2025-01-20 02:18:25 -05:00
parent 0dd22a2682
commit 8b451ff045
5 changed files with 141 additions and 11 deletions

30
labs/classes/fileio.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream inputFile("input.txt");
if (!inputFile.is_open()) {
std::cerr << "Failed to open the user data file." << std::endl;
exit(1);
}
std::string name, gender, number, profession, school;
int age;
double latitude, longitude;
while(inputFile >> name
>> age
>> gender
>> number
>> profession
>> school
>> latitude
>> longitude){
std::ofstream outputFile("output.txt", std::ios::app);
outputFile << name << "," << number << std::endl;
outputFile.close();
}
inputFile.close();
return 0;
}