who's program is it..???
why do you have it....??!??!
more importantly, can I have a cut of what he is paying you..?
who's program is it..???
why do you have it....??!??!
more importantly, can I have a cut of what he is paying you..?
sry to make this so confusing. in need the function called updateCounter. and what it should do is to update the map to show if i have it the target or not. hope that was clearer.
Translation:
"I'm sorry to make this so confusing. I need to develop a function called, 'updateCounter.' It should update the map to show if I have hit the target or not."
It appears that you load a 2 dimensional array with ship positions. You should compare user input to the corresponding element of the array. If the element is occupied, then return hit, else return miss.
If hit, make a 'hit' assignment to the array, else update the array with a miss indication.
Redraw the array and prompt for next user guess.
You are in charge of a high profile software design consulting firm. A customer bursts through the front door, comes running in flailing his arms wildly about, stops at your cubicle, looks you square in the eye and makes the following demand:
the ocean file has to be made separately by 15 by 15, but this is simple and i can do this. what i need help with is the update counter. which is i think to update the map. plese help me out!!!
Q: How do you respond...
Firstly, your evaluations of boolean expressions are incorrect.
Rule of thumb: boolean logic is handled per expression, or as a stand-alone TRUE/FALSE flag.
In your loop condition, you are trying to handle everything at once. It is important that each individual expression be able to resolve to true or false.
I would code you up an efficient way to handle your loop condition; however, without seeing your code, anything that I give you at this point would be based on speculation.
Sooooooo...... do you need help with anything......?
Here another idea..
The problem might be in line #71, where you pass in an argument as a char*
I'm thinkin' since you are using a 2d array, maybe try passing stuff in as a char**
T** maxn(T** a, const int n)
In order to get done what you want done, you'd have to make an array of pointers...
//This will result in the 'const char' that you are trying to avoid
char strs[numStrs][maxLength];
//Try this:
//Dynamically allocated 2d array
char** strs = new char*[numStrs];
for(int i=0; i<numStrs; i++)
strs[i] = new char[maxLength];
//Now you should be able to pass in the array as a 'cstring'(char*)
//as opposed to a 'char literal' (const char array)
if(std::strlen(a[i]) > std::strlen(a[longest]))
Just out of curiosity, have you tried performing the file operations while opened in binary mode?
//sometimes when I can't figure stuff out, I'll see if the same behavior
//exists in binary mode:
preprocess.open ("data//dataset.dat", ios::out|ios::binary);
recordList.open ("data//answers.dat", ios::out|ios::binary);
Your code looked pretty good, and just glancing over your code, I was kinda stumpted at first, but I think I might have a possible solution for ye'...
I believe that your .dat files contain a bunch of stuff. You read in the files succesfully without incident.
I believe the problem occurs when you open the files for writing using your ofstream objects; you open the files in the default mode (ios::out) which is fine... but I do believe the file 'put' pointer is set to the beginning of the files by default (this is not specifically mentioned in the documentation for ofstream's open() function... this conclusion is based soley on my experience.)
My suggestion is to open your files with your 'ofstream' object using the ios::ate flag to ensure that you are not attempting to over-write existing file data (which I think can lead to unpredictable performance):
//Feel free to use the bitwise OR operator to combine flags to meet your needs
preprocess.open ("data//dataset.dat", ios::out|ios::ate);
recordList.open ("data//answers.dat", ios::out|ios::ate);
Now you should be able to append data 'at the end' of your files.
#include<algorithm>
double populateArray(int numberOfElementsToStore[] )
{
int i = 0 ;
for (int i = 0; i < ARRAY_SIZE; i++)
{
numberOfElementsToStore[i] = 10 + 25 * ((double) rand( ) / (double) RAND_MAX ) ;
}
//This will make like values reside next to each other in the array
sort(&numberOfElementsToStore[0], &numberOfElementsToStore[ARRAY_SIZE]);
//This will remove consecutive like amounts
unique(&numberOfElementsToStore[0], &numberOfElementsToStore[ARRAY_SIZE]);
return i ;
}
unique
function template<algorithm>template <class ForwardIterator>
ForwardIterator unique ( ForwardIterator first, ForwardIterator last );template <class ForwardIterator, class BinaryPredicate>
ForwardIterator unique ( ForwardIterator first, ForwardIterator last,
BinaryPredicate pred );
Remove consecutive duplicates in rangeRemoves the duplicate consecutive elements from the range [first,last). This is done by removing all the elements that compare equal to the element right preceding them (only the first element in each group of consecutive equal elements is kept).
This does give me numbers, but not distinct. Thanks!
dis·tinct (d-stngkt)
adj.
1. Readily distinguishable from all others; discrete: on two distinct occasions.
2. Easily perceived by the senses or intellect; clear: a distinct flavor.
3. Clearly defined; unquestionable: at a distinct disadvantage.
4. Very likely; probable: There is a distinct possibility that she won't come.
5. Notable: a distinct honor and high privilege.
I don't understand what you mean by 'distinct' numbers.. do you mean 'unique'? (a number only used once within your array?)
White box testing (a.k.a. clear box testing, glass box testing or structural testing) uses an internal perspective of the system to design test cases based on internal structure. It requires programming skills to identify all paths through the software. The tester chooses test case inputs to exercise paths through the code and determines the appropriate outputs.
Definition from Wikipedia
Here you test the limits of your code design and data structures.
Black box testing takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object’s internal structure.
Definition from Wikipedia
Here you test the limits of user stupidity.
The problem with your program is in it's design.
Here you throw everything inside of a huge loop... and yes, since you are testing eof() which is highly unrecommended, the loop will make at least 2 iterations:
ifstream myfile("BankData.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
myfile>>loginName;
myfile>>password;
if(loginName == loginName1 && password == password1)
{
menu();
}
else
{
cout<<"\tUnregistered ID or you have enter a wrong password !"<<endl;
cin.clear();
cin.ignore();
getchar();
return ;
}
myfile.close();
}
}
Not only that, you close() your ifstream obect, so on the 2nd iteration, your loop condition will fail.. causing your program to close.
Now, I will attempt to fix this mess:
if (!myfile.is_open())
{
cout << "\a\nError! File did not open.";
cout << "\nCheck if file exists, is in specified location, has been renamed, or deleted.";
cout << "\nProgram will now terminate in preparation for file troubleshooting.";
cout << "\nPress [Enter] to exit program... ";
cin.get();
exit(EXIT_FAILURE);
}
myfile>>loginName;
myfile>>password;
if(loginName == loginName1 && password == password1)
{
menu();
}
else
{
cout << "\tUnregistered ID or you have enter a wrong password !" << endl;
cin.clear();
cin.ignore();
getchar();
return;
}
myfile.close();
This is just one implemented solution of many possible. I know it's probably not exactly what you want. Feel free to tweak it as necessary to come up with your own solution.
couple things:
You are using cstring library functions, without explicitly including the <cstring> header. If it works, hey that's fine. Just letting you know.
By putting your array counter at the beginning, you'll always skip over element[0]... I think this is why you are reading the same thing over and over whenever you try to access the first element of your arrays:
while(inFile)
{
count++;
inFile >> lastName[count];
inFile >> firstName[count];
inFile >> phoneNumber[count];
inFile >> email[count];
}
I would put your counter at the end, so your first loop iteration will result in count equal to zero.
The block of code you just provided us appears that it would work as desired. Use of eof() is discouraged, but I don't see it as a major problem here.
You originally threw over 600 lines of code at us with a "Help me it doesn't work" type of request.
A better way to pose your question would be to tell us what part specifically doesn't work, what output you expect, and what output you are currently getting. Also, since this problem deals with file i/o, of course, we'll need to see a sample of your file.
In line #20 you declare a single object of type 'Employee'
In line #33 you attempt to dereferrence e using subscripts.. on your single 'Employee' object.
In lne #35 you again attempt to dereferrence your single e object using array subscripts.
You do not actually create an array of 'Employees' until line #48.
Since you are declaring 'p' locally from within the function, it will be destroyed with the function.. just as any locally declared function variable.
Additionally, you declare 'p' and it is never assigned anything. Later in your function you attempt to dereferrence a NULL pointer.
So the answer is, to declare a gobal variable named 'p' inside of int main() that you can pass into all your functions.
//This is where I want to access p but don't know how.
The variable named 'p' does not exist anywhere within the scope of your Reposition() function.
Either pass it in from elsewhere or declare a local var named 'p'.. if this is what you desire.
So far, a variable named 'p' only exists as a local variable inside of the Search2() function.
Could it be possible for me to read the file name as a string, and add the extension ".output" to the string, and then convert it back to an array of chars?
I'm glad you mentioned this. String class objects are very versitle and can handle virtually any input the user might throw at you.
If we look at the open() function from <fstream>, we see that it has a const char* (cstring) parameter as it's first argument.. which is the file name in a cstring:
fstream::open
public member function
void open ( const char * filename, ios_base::openmode mode = ios_base::in | ios_base::out );
But we are using a string.. what are we supposed to do? Luckily, there is a <string> class member function called c_str() which returns a cstring pointer:
const char* c_str ( ) const;
Get C string equivalent
Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.A terminating null character is automatically appended.
Knowing all this, we can take all user input in the form of a string, concantinate the string with the required file identifier (.txt) and pass the string into the open() function by calling the c_str() member:
#include<string>
string name;
cout << "Enter file name: ";
cin >> name;
//Check to see if user already appended the file type
if(name.find(".txt") == string::npos)
{
//If user did not add file …
My bad.. i told you I was in a rush to save my noodles. Would have liked to have seen more effort on your part with simple debugging:
for(int loopcounter=0; loopcounter<5; loopcounter++)
{
switch(loopcounter)
{
case 0: cout << "Grade A: |"; break;
case 1: cout << "Grade B: |"; break;
case 2: cout << "Grade C: |"; break;
case 3: cout << "Grade D: |"; break;
case 4: cout << "Grade F: |"; break;
}
//loop to output each asterisk
for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
{
cout << '*';
}
cout << "| " << array[loopcounter] << '%'<< endl;
}
I just made this up because I am currently cooking macaroni and cheese, and I think my noodles are being overcooked as we speak.
However, give this a try. If the output is not what you desire, feel free to tweak it as necessary before asking how to improve it:
for(int loopcounter=0; loopcounter<6; loopcounter++)
{
switch(loopcounter)
{
case 0: cout << "\nGrade A: |"; break;
case 1: cout << "\nGrade B: |"; break;
case 3: cout << "\nGrade C: |"; break;
case 4: cout << "\nGrade D: |"; break;
case 5: cout << "\nGrade F: |"; break;
}
//loop to output each asterisk
for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
{
cout << '*';
}
cout << "| " << array[loopcounter] << '%';
}
After assigning a player move to the game_grid[][], in order to display the newly updated board, just use a nested loop to walk through your array, displaying all elements to the screen:
void display(int board[][])
{
//Display all contents of the array
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
cout << board[i][j];
}
That is an excellent question, and I will break it down for you:
Compile, run and enjoy.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string mystr;
double price=0;
double pay = 0;
int quantity=0;
cout << "Enter price: ";
getline (cin,mystr);
stringstream(mystr) >> price;
cout << "Enter quantity: ";
getline (cin,mystr);
stringstream(mystr) >> quantity;
cout << "Total price: " << price*quantity << endl;
cout << "Pay: ";
getline (cin,mystr);
stringstream(mystr) >> pay;
cout << "Change: " << pay - price*quantity << endl;
return 0;
}
I was all for integer division, and I believe it would have worked in that it would just truncate any decimal value to a whole integer.
But I guess this was not the case this time.
Change all your int's to doubles (or floats.. remember to set your precision) and I think you'll be happy with the results.
I am doing my best to imagine your current code...
I was wondering if you could help me out by posting what you have thus far.. if you don't mind.
You are probably displaying too many asterisks.
Each asterisk is supposed to represent 2% as per assignment requirement.
As of now, each asterisk represents 1%.
Therefore, you will have to reduce your asterisk output by 1/2:
for(int asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)
Are you kidding me?
cout<<"Please enter how many grade E's"<<endl;
cin>>e;
Use basic math to calculate a percentage for each letter grade:
Acent = a / total * 100;
Bcent = b / total * 100;
Ccent = c / total * 100;
Dcent = d / total * 100;
Fcent = f / total * 100;
This will give you the overall average grade:
average = (Acent+Bcent+Ccent+Dcent+Fcent) / total;
I'm very new to C#
Do you think asking for homework help in a c++ forum will further your efforts in learning c pound?
You seem like an intelligent individual.. give this a try. We'd love to see your code.
As per the c++ tutorial for accepting user input, try adding this line after line #24:
cin.ignore(100, '\n');
You've brought up a good point; the >> extraction operator is 'white space' delimeted.
If you want to read the entire line, try using the getline() function from <string>
#include<string>
getline(cin, employee[counter].name);
Why ruin a good thing you already got goin'?
//this
gets(employee[counter].name);
//should be this
cin >> employee[counter].name;
I am really not sure where you got "gets()" from.. I think it's a C function... and if I'm not mistaken it's use can be somewhat dangerous.
In my opinion, it is time to remove the gets() function from your c++ repertoire as I have never seen it's use in any code thus far in this forum... or in any other c++ code I have ever seen.
New and improved version:
#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
//var declarations
int length = 0;
char* buffer = new char[17];
buffer[16] = '\0';
vector<char*> cstrings;
//create ifstream object for reading from a file
ifstream infile;
//attempt to open a file
//in this case, since we are dealing mostly with ascii chars
//it is better to open in regular default ascii mode.
infile.open("C:\\Users\\Dave\\Documents\\test.txt");
//perform error checking
if(!infile.is_open())
{
cout << "\aError opening file!";
cin.get();
exit(EXIT_FAILURE);
}
int i=1;
//read in file in 16 byte segments, or as much is left until end of file
while(infile.readsome(buffer, 16))
{
//take out '\n' newlines for console formatting purposes
replace(&buffer[0], &buffer[16], '\n', ' ');
//display exciting information to the user
cout << "\n\nBock #" << i << ": " << buffer;
cout << "\nChar count: " << infile.gcount();
//save our buffer in an 'array type' STL container
cstrings.push_back(buffer);
//create new buffer
buffer = new char[17];
//ensure 'cstring style' null termination
buffer[16] = '\0';
//perform sleep operation
Sleep(500);
//step up the block number
i++;
}
//close the ifstream object since we no longer need to read from a file
infile.close();
return 0;
}
Check this out and see if you have any questions about this working program:
#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
//var declarations
int length = 0;
char buffer[17];
vector<char*> cstrings;
//create ifstream object for reading from a file
ifstream infile;
//attempt to open a file
//in this case, since we are dealing primarily with ascii chars
//it is better to open in regular default ascii mode.
infile.open("C:\\Users\\Dave\\Documents\\test.txt");
//perform error checking
if(!infile.is_open())
{
cout << "\aError opening file!";
cin.get();
exit(EXIT_FAILURE);
}
int i=1;
buffer[16] = '\0';
//read in file in 16 byte segments, or as much is left until end of file
while(infile.readsome(buffer, 16))
{
//take out '\n' newlines for console formatting purposes
replace(&buffer[0], &buffer[16], '\n', ' ');
//display exciting information to the user
cout << "\n\nBock #" << i << ": " << buffer;
cout << "\nChar count: " << infile.gcount();
//save our buffer in an 'array type' STL container
cstrings.push_back(buffer);
//perform sleep operation
Sleep(500);
//step up the block number
i++;
}
//close the ifstream object since we no longer need to read from a file
infile.close();
return 0;
}
Although I am not an <sstream> expert (don't use it that much) I am kinda skeptical about this code:
while(Read.get(buffer[i], 17))
{
for(j=0; j<=16; j++)
oss << buffer[i][j];
It seems to me like you are continually just overwritting the value inserted into your 'oss' object... to me, this would seem a more viable method:
while(Read.get(buffer[i], 17))
{
oss << buffer[i];
cout << "Contents : " << oss.str() << endl;
i++;
}
I have everything I need in the code except the "between 100 and 1000."
//Line #28 should be this:
popList[i] = rand( ) % 901 + 100 ;
Just add a sleep function of some sort in the file reading loop (after line#19 perhaps).. otherwise, the above code will meet your stringent requirements, reading the file contiguously from the point it left off.
@ Clinton Portis :
I tried using seekg(), but my intended output was much different. Could you look into this?
without even looking, I will guess that your file has not been opened in binary mode; in which case, I would highly recommend doing so whilst messing about with file pointers.
[Edit]
Ok.. you opened in binary.. I'll look into this a bit and see if I see anything.
Line#19: You are reading the file based on the current condition of the eof() fail bit flag, not recommended.
Lines#27 thru #33: You are attempting to seekg() to your current position....... which, you are already at :rollseyes:
I am going to make a few assumptions here and attempt to help you out.
1. You are attempting to read in the file in a contiguous manner.
2. You would like to break up the file into 16byte chunks.
With this in mind, we can focus strictly on the task at hand:
//Get the size of the file
Read.seekg(0, ios::end);
length = Read.tellg();
Read.seekg(0, ios::beg);
//Create a buffer to meet our needs
char* buffer = new char*[length];
for(int i=0; i<length; i++)
{
buffer[i] = new char[17];
buffer[i][16] = '\0';
}
//Read the file in 16byte segments or eof(), whichever comes first
//Testing the return condition of the function is preferred, as opposed to testing eof()
int i=0;
while(Read.get(buffer[i], 16))
{
i++;
}
There you have it... simple, straight forward, no unecessary …
I am glad you asked. Use the seekg() function to move about in your file as ye' wish:
istream::seekg
public member functionistream& seekg ( streampos pos );
istream& seekg ( streamoff off, ios_base::seekdir dir );
Set position of the get pointerSets the position of the get pointer.
The get pointer determines the next location to be read in the source associated to the stream.
Parameterspos
The new position in the stream buffer. This parameter is an integral value of type streampos.off
Integral value of type streamoff representing the offset to be applied relative to an absolute position specified in the dir parameter.dir
Seeking direction. It is an object of type ios_base::seekdir that specifies an absolute position from where the offset parameter off is applied. It can take any of the following member constant values:
value offset is relative to...ios_base::beg beginning of the stream buffer
ios_base::cur current position in the stream buffer
ios_base::end end of the stream bufferReturn Value
The function returns *this.
So just call a seekg(position) whenever you want to set the 'get pointer' to a position where ye' would like to start reading from the file. Then I would call the readsome() function to read in a chunk of the file.
Keep in mind, if you are reading the file in a contiguous manor, the 'get pointer' will be at the position where you left it, in …
I'm trying to do a concatenation function I do not want to you use the strings property where we can add strings, I need to add two strings and save them in one string without the use of addition "+"
Instead of trying to decipher your code, I will offer a pseudo-coded solution:
char* concat(string& first, string& second, char* buffer);
string first = "We think in generalities ";
string second = "but we live in details.";
char* concat(string& first, string& second, char* buffer)
{
int length = 0;
//Get length of first string
length = first.size();
//Add to length of second string
length += second.size();
//Allocate enough memory for a cstring buffer
buffer = new char[length+1];
//Ensure cstring null termination
buffer[length] = '\0';
//Perform concantination
int i=0;
while(first[i] != string::npos)
{
buffer[i] = first[i];
i++;
}
int j=0;
while(second[j] != string::npos)
{
buffer[i] = second[j];
i++;
j++;
}
return buffer;
}
I have to read 16 bytes using the low-level function call read() (in C). After I read the first 16 bytes, the next time I need to read from the same file, I'll only have to read it from until the point it was read before..
Since you only require to read in a certain amount of the file (as opposed to reading in the entire file at once) I think readsome() function may be a more appropriate choice:
istream::readsome
public member function
streamsize readsome ( char* s, streamsize n );
Read block of data available in the buffer
Reads a block of data of up to n characters and stores it in the array pointed by s, but unlike member function read, readsome stops reading if the memory buffer associated with the stream runs out of characters, even if the End-Of-File has not yet been reached.Return Value
The number of characters extracted.Errors are signaled by modifying the internal state flags.
With this in mind, I would propose using the readsome() function and reading the file into a char[16] buffers (or char[17] if you would like to provide null termination which will allow you to use <cstring> functions safely)
Since you would probably need to use several char[16] buffers, let's create a bunch of them:
char buffer[100][16];
A more optimal alternative of course, would be to dynamically create an array of specific size based on the number of characters in your file:
…I think you mean to do this, if your2darray is an array of cstrings:
//this
your2darray[x][y] = "asdf";
//should be this:
strcpy(your2darray[x], "asdf");
I was just driving down the road and I was thinking, "Hmm.. i forgot to allocate memory for each char* of the vector... so I think this will work better:
for(int i=0; i<wordcount; i++)
{
char* temp = new char[20];
cout << "Enter a word (19 chars or less): ";
cin >> temp;
words.push_back(temp);
}
Pecet, I was first considering a 'vector of a vector of char pointers' I soon realized that was overkill.. a simple vector of char* is similar to a char[][] 2d array.
ghering,
MyArray[0][1]="hello"
will give you the 'e' in "hello".. if you wanted to access the entire word, just dereferrence the first dimension, which is a pointer to the beginning of the cstring
cout << MyArray[0];
As long as the 2nd dimension is null terminated, your cout operation will not run out of bounds into the rest of the array.
What you are asking for can be a very useful data structure... if created dynamically can have about the same performance as a vector and might even be more efficient (a vector might allocate more memory than what you actually need based on the number of push_back() opearations) In either case, here is how you can do both:
The creation of a 2d array is like having a 'pointer to a bunch of pointers':
//create the array pointer (holds the address to the beginning of a block of allocated memory)
//create 2d array of pointers to cstrings
char* words = new char*[wordcount];
//allocate memory for each cstring pointer
for(int i=0; i<wordcount; i++)
{
wordcount[i] = new char[20];
}
//Now you have words[word#][individual char] array of cstrings, each can hold a word of (in this case 19 chars or less)
//Now you can perform cool cstring operations:
//'Add' to an existing cstring (in this case, the second cstring of the array)
strcat(words[2], " a good day");
If you want to use more modern c++ techniques as opposed to using the older C style character arrays, here is how ye' would declare a 'vector of char vectors'
//Notice that this is one of the very few instances in c++ where spacing matters
//Be sure to add a space in between the > > or else your compiler will think it's a >> extraction operator
vector<char*> words;
//create a temporary cstring we will push into the vector anytime we want …
I think the problem is here...
for (int i=-1;ip!=" ";i--)
Since you are using the 'end' flag in seekg(), all offset is relevent to the end of the file.. therefore, you should increment your way from the end of the file, stepping your way backwards into the text file.
You might also have a problem with initializing 'i' to -1.. keep this in mind if you continue to have problems.
Also, I would highly recommend opening your file in binary mode when messing about with the file pointers.. for some reason, when opened in regular ascii mode, it seems to dramatically affect the pointer offset position (you think you are at one place when you are really not)
You have an interesting scheme in place here, getting the line after each character test...
Looks like ye' need to perform a good ol' int-to-string conversion. Today we'll be creating an 'ostringstream' object derived from the <sstream> library in order to facilitate our int-to-string needs:
#include<sstream>
#include<string>
#include<iostream>
using namespace std;
int main()
{
ostringstream int_to_str;
string temp;
int a = 0;
cout << "Enter a number fool: ";
cin >> a;
int_to_str << a;
temp = int_to_str.str();
cout << "String " << temp << " == int " << a;
return 0;
}
Is the buffer NULL terminated..???
Getting garbage at the end of a cstring is a common sign of mising NULL termination. After briefly looking at the getcwd() documentation, it does not say anything about providing a null terminator at the end of the array.
//Also this
}while(c >= 'A' && c <= 'Z');
//should be this
}while(c < 'A' && c > 'Z');
I like your solution in that it opens the file with the get ponter already set to the end of the file.
I opted to use the the ios::end flag in setg() though because then I can just increment my way from the end of the file until I get to where I want to go.
Perhaps the best solution would have been to combine our efforts; open the file 'at the end' and then seekg( , ios::end) step backwards through the file.