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
cout
// 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.
fileStream.seekg(0,ios::end);
int NumberOfRecords = fileStream.tellg () / sizeof(SalesRecord);
cout
// 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.
system("PAUSE");
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
srand(0);
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" on May 1
 *Thanks MC, worked perfectly.Unseen on May 1
  * :-) on May 1
More problems..Unseen Machine on May 1
 Does that compile? on May 1
  Its all appreciatedUnseen on May 1
   Are you unchecking "Enable formatted text" when you post? on May 1
    NopeUnseen on May 1
     Much better. on May 1
      Thanks MC.Unseen on May 1
       You're welcome. on May 2
        Well, this one outputs binaryUnseen on May 2
         Yes, it does. on May 2
          Erm..Unseen on May 2
           This one seems to work :-) on May 2
            You the man MC!Unseen Machine on May 2
             *yw 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... on May 2
                Thanks again MCUnseen on May 2
                 arrays... (edited to fix post) on May 3
                  Multidimensional arrays and expandable arrays in C++ on May 3
           fstream vs ifstream/ofstream (and other things about your code) on May 2
            Re: fstream vs ifstream/ofstream (and other things about your code) on May 2
             (FIXED) Well, I'm not sure how well defined the behaviour is, but... on May 3
              *Thank you. on May 3
      *oops. "delete SalesRecs;" should be "delete [] SalesRecs;" on May 2
ARGHH!!!Unseen on May 7
 Sorry to hear that, Unseen. on May 7
 * likewise, sorry to hear that. on May 7
My version of the original with the binary file I/O, minus the menu and other things on May 8

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