B
blip
Is this acceptable ? It seems too easy and too simple...
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
struct Person{
char name[25] ;
int age ;
char ssn[9] ;
} person[5] ;
int main(int argc, char *argv[])
{
std::ifstream input ;
std:fstream output ;
std::string name ;
int age ;
input.open("file.txt", std::ios::in) ;
output.open("fileout.txt", std::ios:ut) ;
if(!input){
std::cout << "File not found" << std::endl ;
exit(1) ;
}
for(int i = 0; i < 5; i++)
input >> person.name >> person.age >> person.ssn ;
for(int k = 0; k < 5; k++)
std::cout << person[k].name << " " << person[k].age << " " <<
person[k].ssn << std::endl ;
// write some text to a file
name = "Me" ;
age = 105 ;
output << name << " " << age << std::endl ;
return 0 ;
}
Here's the file contents exactly as in file.txt
bob
44
123-23-4532
fred
61
434-98-7654
hilbert
23
772-81-7108
peter
12
132-64-0132
jake
51
565-61-0909
I'd like to know what you people think of this .
Regards,
Me
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
struct Person{
char name[25] ;
int age ;
char ssn[9] ;
} person[5] ;
int main(int argc, char *argv[])
{
std::ifstream input ;
std:fstream output ;
std::string name ;
int age ;
input.open("file.txt", std::ios::in) ;
output.open("fileout.txt", std::ios:ut) ;
if(!input){
std::cout << "File not found" << std::endl ;
exit(1) ;
}
for(int i = 0; i < 5; i++)
input >> person.name >> person.age >> person.ssn ;
for(int k = 0; k < 5; k++)
std::cout << person[k].name << " " << person[k].age << " " <<
person[k].ssn << std::endl ;
// write some text to a file
name = "Me" ;
age = 105 ;
output << name << " " << age << std::endl ;
return 0 ;
}
Here's the file contents exactly as in file.txt
bob
44
123-23-4532
fred
61
434-98-7654
hilbert
23
772-81-7108
peter
12
132-64-0132
jake
51
565-61-0909
I'd like to know what you people think of this .
Regards,
Me