Δημοσιεύτηκε: 04 Φεβ 2009, 14:05
από thodoris_turtle
συγνωμη αλλα δεν μπορω να γραψω απεριοριστο κειμενο στον τιτλο για να βαλω οτι το προβλημα επιλυθηκε


Γλωσσα C++--Προβλημα-απορία σχετικα με τα επιπεδα προσβασης(private,public,protected ) στα member μιας κλασης
Κώδικας: Επιλογή όλων


#include<string>
#include<vector>
#include<iostream>
#include<fstream>

using namespace std;

class Person{
public:
string name_;
int age_;

Person(string n,int a)
{
name_=n;
age_=a;
}
};

int main()
{
vector<Person> addressbook;

const int linesize=100;
char input[linesize];
int age;

for(int i=0;i<5;i++)
{
cout<<"Enter Name:";
cin.getline(input,linesize);

cout<<"Enter Age:";
cin>>age;

addressbook.push_back(Person(input,age));

cin.getline(input,linesize);

}

ofstream fout("address.txt");
if(fout==0)
{
cout<<"Error! cannot open file address.txt"<<endl;
return 10;
}

cout<<"Writing results to file address.txt"<<endl;

for(int j=0;j<addressbook.size();j++)
{
fout<<addressbook[j].name_<<" is "
<<addressbook[j].age_<<" years old"<<endl;
}

//close file

fout.close();
return 0;
}

/*
class Person{
private:
string name_;
int age_;
public:
Person(string n,int a)
{
name_=n;
age_=a;
}
};


mou emfanizi to akoloutho error oti to _name einai private ti na kanw ;
*/