include iostream include fstream include string include stdlib using n

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
const int l_name = 30,
ifstream fin("text.txt"/*,ios::in | ios::nocreate*/);
if(!fin){cout<<"Cant open file"<<endl; return 1;}
int i=0;
while (fin.getline(buf,l_buf)){
if (i>=l_dbase){cout<<"too long file"<<endl;return 1;}
strncpy(dbase[i].name,buf,l_name);
dbase[i].name[l_name]='\0';
dbase[i].birth_year=atoi(&buf[l_name]);
dbase[i].pay=atof(&buf[l_name+l_year]);
++i;
}
return 0;
}