473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

need some oversight

Hi all,

This is my first time posting so please bear with me.

I would like some criticism of some elementary C++ work I'm doing because
it's been a long long long time and I'm not sure if I'm doing things
correctly/safely.

Particularly I'm having trouble remembering proper use of input streams.
The code I came up with follows at the bottom of the post.

Simply what I need to do is read a file from beginning to end, in hex.
Here is a sample of input:

0 1000
0 2000
0 3000
1 2000
0 4000
2 5000
2 1000

Kind of irrelevent but possibly of interest. The first column of numbers is an action; read,
write, instruction fetch. The second column of numbers is a virtual
address.

The final goal of this program (by Tuesday) is to simulate a handful of
page replacement algorithms.

Regards,
Grant

#include <iomanip.h>
#include <iostream.h>

int main(int argc, char * argv[]) //will be used for cmdline switches
// all input files will come from std input eg. a.out < belady.din
long int a,b;

while(!cin.eof()){
if(!cin.eof())
cin >> hex >> a >> hex >> b;

/* do everything important */

if(!cin.eof())
cout << a << b << endl;
}

}
Jul 22 '05 #1
4 1529
Update:The issue I'm noticing is that the last entry is output(read)
twice.

Jul 22 '05 #2
On Sat, 06 Dec 2003 02:12:50 +0000, Grant Austin wrote:
Update:The issue I'm noticing is that the last entry is output(read)
twice.

yet further clarification: that is the last entry is output(read) twice
when I remove the cin.eof statements which IMHO seem a tad kludgy
Jul 22 '05 #3

"Grant Austin" <ga*****@foo.foo.bar.net> wrote in message
news:pa****************************@foo.foo.bar.ne t...
Update:The issue I'm noticing is that the last entry is output(read)
twice.


I'm a little rusty on my C++ as well, but I believe you may need to use a
priming read OR on the last itteration the last line has been read but the
EOF is NOT yet been read (C++ does not read ahead).
Jul 22 '05 #4
Grant Austin wrote:
Hi all,

This is my first time posting so please bear with me.

I would like some criticism of some elementary C++ work I'm doing
because it's been a long long long time and I'm not sure if I'm doing
things correctly/safely.

Particularly I'm having trouble remembering proper use of input
streams. The code I came up with follows at the bottom of the post.

Simply what I need to do is read a file from beginning to end, in hex.
Here is a sample of input:

0 1000
0 2000
0 3000
1 2000
0 4000
2 5000
2 1000

Kind of irrelevent but possibly of interest. The first column of
numbers is an action; read, write, instruction fetch. The second
column of numbers is a virtual address.

The final goal of this program (by Tuesday) is to simulate a handful
of page replacement algorithms.

Regards,
Grant

#include <iomanip.h>
#include <iostream.h>
Those are not standard headers. Use <iomanip> and <iostream> instead.
However, cin, cout and endl will be in namespace std, so you must
qualify them like std::cin.
int main(int argc, char * argv[]) //will be used for cmdline switches
// all input files will come from std input eg. a.out < belady.din
long int a,b;

while(!cin.eof()){
if(!cin.eof())
That if() is redunant, since the loop will only be entered if cin.eof()
is false.
cin >> hex >> a >> hex >> b;

/* do everything important */

if(!cin.eof())
cout << a << b << endl;
}
You are using eof() the wrong way, since eof() will only be true _after_
you tried to read past the end. This means that your loop will be
entered once too often. Further, you will get an endless loop if the
stream can't be read for any other reason than eof. You could write it
like this:

while(std::cin >> std::hex >> a >> std::hex >> b)
std::cout << a << b << std::endl;

if (!std::cin.eof())
std::cout << "Read error\n";

}

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tommy | last post by:
I am a complete beginner in regular expressions and would need some help from the group regarding checking a form field. I have a field on the form where users enters a text string. The user...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
2
by: Richard Myers | last post by:
Howdy, I haven't struck this before.... I am visually inheriting several forms from another. All works well but then i thought i'd create an enum that is used only by this form - not even its...
85
by: | last post by:
List, I'm looking for C links for Standard C for a website targeting professional SW engineers. Intent is to have a convenient reference to Standard C, particularly for those who come from...
6
by: Alan Silver | last post by:
Hello, Well, after almost completing my very first real CSS-only design, I'm just trying to iron out the last problems. You can see a mock-up of the page at...
3
by: Lucky | last post by:
hi guys, i'm practising regular expression. i've got one string and i want it to split in groups. i was trying to make one regular expression but i didn't successed. please help me guys. i'm...
12
by: John | last post by:
I can't get my head around this! I have the following code: <% .... Code for connection to the database ... .... Code for retrieving recordset ... If Not rs.EOF Then ... Do something...
31
by: metaperl | last post by:
-- python -i File "<stdin>", line 1 class = "algebra" ^ SyntaxError: invalid syntax Why isn' t the parser smart enough to see that class followed by an identifier is used for class...
25
by: crescent_au | last post by:
Hi all, I've written a login/logout code. It does what it's supposed to do but the problem is when I logout and press browser's back button (in Firefox), I get to the last login page. In IE,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.