Help needed with structures...

by Unseen Machine (no login)

I cant assign values to the variables in the structure! I dont know enough C++ to understan the error report (something about Did i mean -> )

Here's the code (VC++08), any ideas or tips would be great. As you can see it is coursework so please dont just do it for me...

// JohnOnyon_10036178_Coursework1_C++.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "string"
#include "iomanip"
#include "ctime"
#include "cstdio"

using namespace std;

//Prototype function declerations
ifstream& OpenRecords(const char* FilePntr);

//This struct defines how the records file is both built and read.
//4 SalesRecord structures must exist for a complete record section.
//Each SalesRecord is an individual employees sales for that day.
struct SalesRecord
{int Item1, Item2, Item3, Item4, Item5;};

int main ()
// Title
// Get the file stream
ifstream& fileStream = OpenRecords("SalesRecords.txt");

// Count the number of entries, create array to match and load the data.
// This is done by seeking for the end if file flag and dividing the pointers
// position by the size of the SalesRecord structure.
int NumberOfRecords = fileStream.tellg () / sizeof(SalesRecord);
// Create array of SalesRecord struct and store the data in it.
cout while(!fileStream.eof())
int value = 0;
fileStream >> value;

// Allow the user to see the final screen before exit.
return 0;

// This function checks for the records files existance, if it exists, returns a pointer to the
// open file stream, If it does not exist then the program creates a dummy records file and
// restarts.
ifstream& OpenRecords(const char* FilePntr)
// Make sure the records file exists before running the program
cout // Attempt to open the file, if good return pointer of open file stream else report error and exit.
ifstream* CheckFileStream = new ifstream(FilePntr);
if (CheckFileStream->good())
cout }
else // If file not found create a dummy records file and restart the loading.
cout delete CheckFileStream;
ofstream* CheckFileStream = new ofstream(FilePntr);
// Seed random number generator
int MaxSales = 10, MinSales = 0;
int RandNum;

SalesRecord* sRec = new SalesRecord();
RandNum = rand();
sRec.Item1 = (RandNum % MaxSales) + MinSales;

return *CheckFileStream;

Posted on May 1, 2011, 12:29 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
try changing "sRec.Item1" to "sRec->Item1"Michael Calkins on May 1
 *Thanks MC, worked perfectly.Unseen on May 1
  * :-)Michael Calkins on May 1
More problems..Unseen Machine on May 1
 Does that compile?Michael Calkins on May 1
  Its all appreciatedUnseen on May 1
   Are you unchecking "Enable formatted text" when you post?Michael Calkins on May 1
    NopeUnseen on May 1
     Much better.Michael Calkins on May 1
      Thanks MC.Unseen on May 1
       You're welcome.Michael Calkins on May 2
        Well, this one outputs binaryUnseen on May 2
         Yes, it does.Michael Calkins on May 2
          Erm..Unseen on May 2
           This one seems to work :-)Michael Calkins on May 2
            You the man MC!Unseen Machine on May 2
             *ywMichael Calkins on May 2
            Here's my re-writeUnseen on May 2
             2nd Version -Unseen on May 2
              Nearly there...Unseen on May 2
               Re: Nearly there...Michael Calkins on May 2
                Thanks again MCUnseen on May 2
                 arrays... (edited to fix post)Michael Calkins on May 3
                  Multidimensional arrays and expandable arrays in C++ChronoKitsune on May 3
           fstream vs ifstream/ofstream (and other things about your code)ChronoKitsune on May 2
            Re: fstream vs ifstream/ofstream (and other things about your code)Michael Calkins on May 2
             (FIXED) Well, I'm not sure how well defined the behaviour is, but...ChronoKitsune on May 3
              *Thank you.Michael Calkins on May 3
      *oops. "delete SalesRecs;" should be "delete [] SalesRecs;"Michael Calkins on May 2
ARGHH!!!Unseen on May 7
 Sorry to hear that, Unseen.ChronoKitsune on May 7
 * likewise, sorry to hear that.Michael Calkins on May 7
My version of the original with the binary file I/O, minus the menu and other thingsChronoKitsune on May 8

 Copyright © 1999-2018 Network54. All rights reserved.   Terms of Use   Privacy Statement