1P -------------------> class name
4 ---------------------> number of students
Catlin HENDERSON 100
Tessy BARNETT 101
Toma RICE 102
Adora ORTIZ 112
2H ------------------> class name
3 --------------------> number of students
Adora ORTIZ 112
Adora ORTIZ 110
Shani ROSE 112
3Q ---------------------> class name
2 -------------------> number of students
Bathsheba MEYER 105
Dix BUTLER 111
4G
4
Greer FORD 106
Barby SHAW 107
Trude ANDERSON 108
Alla HARRIS 109
5H
0
i have className's cn and studentsNumber's n
1 2 3 4 5 6 7 8 9 10 11
class className
{
public:
string cn;
};
class studentsNumber
{
public:
int n;
};
and i want to send
"class name" to className and
"number of students to "studentsNumber" class
ifstream fin("file.txt");
std::string className; // presumably defined in the class
fin >> className;
int studentsNumber; // presumably defined in the class
fin >> studentsNumber;
Edit: With the classes you just edited in:
1 2 3 4 5 6 7
ifstream fin("file.txt");
className the_className;
fin >> the_className.cn;
studentsNumber the_studentsNumber;
fin >> the_studentsNumber.n;
Your classes are rather silly, why not just use a string and int?
logarech,
Yes, I only showed you an example of how to get the first class name and number of students.
Think about the information this gives you now: You now know the number of students, which corresponds to the number of lines in your file before the next class name/number of students shows up.
which corresponds to the number of lines in your file before the next class name/number of students shows up.
this is true, and nicer than the string length of 2 that I suggested, and is probably what they actually wanted you to do. I was *that* student, didn't really take classroom problems too seriously.