![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 5
| Question about the getline function The Structure: Code: struct student // the student structure meant to hold all student data
// in a linked list fashion
{
char studentNames[maxStudents][lnName]; // student names
int sectionNum; // section the student is in
float project[11]; // student's projects
float test[3]; // students's tests
float quiz[5]; // students's quizzes
student *nxt; // pointer to next student
}; // end struct student
The Function: Code: void getStudentNames (char pgmID[], char title[], char subTitle[],
char gradebookName[] )
{
// Declare local vbls for holding data that is inputted by the user.
int numStudents;
student *temp;
// Display title and sub-title lines.
system ("cls");
cout << pgmID << setw ( 40 + strlen(title) / 2 - strlen(pgmID)) << title << endl;
cout << setw ( 40 + strlen(subTitle) / 2) << subTitle << "\n\n\n";
// If warranted, open the file for output.
ofstream gradeBookFile;
gradeBookFile.open (gradebookName, ios::out);
// Input data for this item from the user and output it to the database.
cout << "\t\tPlease enter the number of students: ";
cin >> numStudents;
cin.ignore();
// Input data for this item from the user and output it to the database.
for ( int count = 0; count < numStudents; count++ )
{
cout << "\n\t\tPlease enter student name (L F MI): ";
temp = new student;
cin.getline ( temp[count] ->studentNames, lnName );
gradeBookFile << temp->studentNames[count] << endl;
} // end for ( int count = 0 ....
// Close the file, return to sender.
gradeBookFile.close();
} // end getStudentNames (...
I don't know how to properly do this HELP PLEASE! |
| jmg0880 is offline | |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,175
| And the error is.... ???? By the way, your struct should look like this: Code: struct student // the student structure meant to hold all student data
// in a linked list fashion
{
char studentNames[maxStudents][lnName]; // student names
int sectionNum; // section the student is in
float project[11]; // student's projects
float test[3]; // students's tests
float quiz[5]; // students's quizzes
struct student *nxt; // pointer to next student
}; // end struct student
__________________ Mac and Windows cross platform programmer. Ruby lover. Quote of the Day 8/19: brewbuck: I do not recommend the above. In fact, it's so disgusting that I've blanked it out because you'd probably take it and run with it. |
| Dino is offline | |
| | #3 |
| Registered User Join Date: Nov 2009
Posts: 5
| The error is : error C2819: type 'student' does not have an overloaded member 'operator ->' and also error C2232: '->student::studentNames' : left operand has 'struct' type, use '.' |
| jmg0880 is offline | |
| | #4 |
| Registered User Join Date: Nov 2009
Posts: 5
| I really need help! |
| jmg0880 is offline | |
| | #5 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,175
| I am home sick today - so this is the best I care to offer right now. When working with structs, when you have one statically allocated, you use dot notation to access its members. When working with pointers to structs, you use arrow notation.
__________________ Mac and Windows cross platform programmer. Ruby lover. Quote of the Day 8/19: brewbuck: I do not recommend the above. In fact, it's so disgusting that I've blanked it out because you'd probably take it and run with it. Last edited by Dino; 11-03-2009 at 09:51 AM. Reason: typo |
| Dino is offline | |
| | #6 | |
| Registered User Join Date: Nov 2009
Posts: 5
| Quote:
| |
| jmg0880 is offline | |
| | #7 | |
| Registered User Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 3,059
| Quote:
Code: for ( int count = 0; count < numStudents; count++ )
{
cout << "\n\t\tPlease enter student name (L F MI): ";
temp = new student;
cin.getline ( temp[count] ->studentNames, lnName );
Any errors in the above I attribute to the Vicodin I'm currently taking... good stuff.
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 There are no stupid questions, only stupid people. 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 | |
| hk_mp5kpdw is offline | |
| | #8 | |
| Registered User Join Date: Nov 2009
Posts: 5
| Quote:
Billy Bob M | |
| jmg0880 is offline | |
| | #9 |
| The Beautiful C++ Utopia Join Date: Oct 2007
Posts: 16,550
| Then it would be temp->studentNames[count] The index comes after the actual variable whose elements you want to access. Disclaimer: I have not checked this for rightness. I am simply explaining how it should be done.
__________________ WARNING: Any and all code samples I post are not tested unless explicitly mentioned otherwise. Use at your own risk. Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Why did the Java creators shoot themselves in the foot? |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| We Got _DEBUG Errors | Tonto | Windows Programming | 5 | 12-22-2006 05:45 PM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| Calling a Thread with a Function Pointer. | ScrollMaster | Windows Programming | 6 | 06-10-2006 08:56 AM |
| c++ linking problem for x11 | kron | Linux Programming | 1 | 11-19-2004 10:18 AM |
| qt help | Unregistered | Linux Programming | 1 | 04-20-2002 09:51 AM |