if(role==2)
{
int arr;
ifstream record("total.txt");
record>>arr;
record.close();
string names[arr];
int age[arr];
ifstream file("names.txt");
ifstream file0("ages.txt");
for(int i=0;i<arr;i++)
{
getline(file, names[i]);
file0>>age[i];
}
for(int i=0;i<arr;i++)
{
cout << left << setw(25)
<< names[i] << " " << age[i] << std::endl;
}
}
here i am reading from two files names and ages. Total.txt contains a number which is number of persons. Here is the output window:
[enter image description here]
after 19 it is showing 0 and 6419936, i dont know why. These 2 numbers are not present in ages.txt. How to get rid of them?
Aucun commentaire:
Enregistrer un commentaire