In C++, where are the header files that define the standard primitives and bitfields?
I would like to confirm something, if it is possible.
-Alex
In C++, where are the header files that define the standard primitives and bitfields?
I would like to confirm something, if it is possible.
-Alex
my wishes:
1. Peace on earth
2. A beautiful Girl-friend (i never had one :'( )
Oddly enough, your avatar scares me... @_@
I have said this before, but...
From the gas station... White chocolate, cheesecake, rootbeer, 1/2 shot Latte O_O
From Starbucks, typically a White-chocolate mocha along with a butter-horn.
And of course I always pay the maker of the coffee to drink it (if they start making weird faces about it ). XD
-Alex
That means you are literally treating something that isn't an lValue as an lValue.
For example if a method doesn't return a reference to something, its possible that attempting to treat the method as an lvalue wont work since you're returning a copy of the actual object in which that copy may not be assigned to anything else...
It's actually hard for me to believe that you can't treat a temporary as an lValue considering potential chained = statements.
I believe this is an appropriate example--
( please excuse the code inlining - I'm in a hurry @_@ )
int method(){
return 9;
}
int& method2(int num){
return num;
}
int main(){
method() = 8; // should throw an error
int x = 10;
method2(x) = 5; // valid since the method returns a reference which can be assigned
a value
}
Edit: Actually its possible that primitive types, which aren't objects, will be the most likely to flag such an error. It's possible that the assignment operator isn't valid for 'const' or temporary types (which makes sense, otherwise you could change the value of the number 9 by assigning it 5 and get the value of 5 instead of 9 wen you need 9... that would be a pain @_@ )
-Alex
>Deliberately crashing the kernel isn't funny
Does that mean accidently crashing it is? :)Hah :D , sorry, I coulden't help myself.
Rep-worthy! XD
It's too bad I can't give you any more rep today @_@
-Alex
If there is already a class available that can search through all of the files on your System, why not make a Decorator class or a class that Maps files (or file names) to a number, and if the file is encountered again, replace the value with an incremented form of the same value, then return the map?
-Alex
I don't know why... but I found the first post amusing XD
But I'm laughing with you Beast! I promise! O_O
-Alex
If you have a finite number of values and they aren't going to change, you can get away with using a standard array instead of a vector.
This is only if you have a static amount of values and performance is an issue. If performance doesn't matter, use a vector as suggested from niek_e since you get the perks of a dynamic array as well as information about its size and the ability to use STL algorithms with it to manipulate, copy or iterate through its contents... etc.
-Alex
The error codes are usually self explanatory, though with Dev-Cpp that can be a different story since the IDE is currently 'dead' (it works, but it is old and I believe it only deals with gcc and old MingW compilers).
Use Code::Blocks or Microsoft Visual C++ 2008 Express edition (recommended). Then again this depends on the type of OS you're using of course @_@.
Don't be discouraged! The majority of the people on this forum will help you when they can (including me XP ). Also if all else fails, copy your error code (or the portion of it that seems to be a recurring theme) and paste it on Google or MSDN. Chances are high that there is some kind of forum post or detailed description of the error floating around on the web!
And good luck! =)
-Alex
void delNeg(node * L)
{
node *cur = L; // cur points to accepted pointer
node *prev = NULL; // prev points to NULL
while(cur != NULL) // while cur doesn't point to NULL
{
if(cur->info < 0) // if the member (of the object on top of the current address) info is logically 'less than' 0
{
prev = cur; // prev points to the address held by cur
cur = cur->link;// cur points to the (next?) address held by its member cur->link
delete prev; // the object that sits on top of the address held by prev
// is destructed and the memory it held is returned to the OS
}
else // if the member (of the object on top of the current address) info is logically 'greater than or equal' to 0
{
prev=cur; // prev points to the address held by cur
cur=cur->link; // cur points to the (next?) address held by its member cur->link
}
}
}
That would be freeing memory held by the member a node had if its member has a logically less-than value.
You're halfway there. You do need a reference to the first Node of the entire list to get to other Nodes, however the way you are currently deleting will most likely pose some problems.
By literally deleting you are invalidating the Nodes. They are technically still 'referenceable' and therefore if you try to use the delNeg again you will most likely run into access …
Use stringstream if you want to append values to a string buffer on one line then extract the string later.
#include <iostream>
#include <sstream>
#include <string>
using std::stringstream;
using std::string;
using std::cout;
using std::cin;
using std::endl;
using std::flush;
int main(){
stringstream ss (stringstream::in | stringstream::out);
string testing = "testing!";
ss << "Testing " << 123 << testing;
string result = ss.str();
cout << result << endl;
cin.get();
return 0;
}
I think this may also be possible with string buffer class, though I haven't experimented with it yet @_@.
-Alex
I tried this (using MS Visual C++ 2005/2008) and it managed to work--
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::flush;
int main(){
char str1[] = "Hello";
char* str2 = str1;
str1[0] = 'M';
cout << str2 << endl;
cin.ignore();
cin.get();
return 0;
}
-- however when I tried your snippet of code--
char* str1 = "Hello";
char* str2 = str1; // What happens here
-- and used similar syntax mentioned above, I kept getting an access violation.
The only 2 conclusions I can guess are that in MSVC++ anonymous const char* strings don't really belong to the application. Either that or somehow the implementation may prevent modification for chars that are const (but I hardly believe this, though I've been surprised with MSVC++ quite a few times now so I don't want to throw that possibility out of the window @_@ ).
What compiler are you using?
-Alex
If possible, please post the solution.
Maybe you didnt understand what i mean,
A behavior(function) is belong to a object, it can not exist seprately.
In the situation of this problem, it is definitely correct.1.) Virtual
2.) Static
3.) Callback
4.) Delegation
the Polymorphism features you mentioned above are also defined in 'object' scope or 'class' scope(e.g.static).
1) virtual function , even if it is a virtual method, its behavior can be overridden within an inheriting class by a function with the same signature. this function must have specific behavior in runtime, at that time , it must belong to a specific object .
2) Static. in this case, a behavior is belong to the whole class , and every object of this class shares this behavior. Although it is not belong to a single object , it BELONG TO a class. it can not exist separately ,either.
3) Callback. Strictly speaking, i dont think callback belongs to OOP, any executable code that is passed as an argument to other code can be a type of callback.
4) Delegation. in c# programing, you can easily find this feature . it seems like a pointer of a function in c/c++. And also, i don't think it contains any OOP features.
Static isn't defined strictly for classes. Static implies that something is resolved at compile-time (or in Java, something is used for the first time (Static Fields)). If this is hard to believe, refer to the use of …
Ok, where is the confusion really? An API that specialized in SMTP and POP3 or the concept of SMTP and POP3 protocols?
-Alex
Post the code please. I can see a few ways around this but it might be better to have a sense of the intent of the program before making a suggestion.
The problem may be that the compiler sees a possibility of your .cpp file attempt to define something that doesn't exist, since your header file is conditionally defined.
You can make it, such that, the text in your implementation file is read by the compiler if and only if the header is defined--
#ifdef STACK_H
template <class T> stack<T>::stack()
{
}
template <class T> stack<T>::~stack()
{
}
template <class T> void stack<T>::push(T c)
{
lst.Insert(c) ;
}
template <class T> T stack<T>::pop()
{
T c = lst.get_head_suffix() ;
lst.Remove() ;
return c ;
}
template <class T> bool stack<T>::is_empty()
{
if (lst.get_head() == 0)
return true ;
else
return false ;
}
template <class T> T stack<T>::peek()
{
if (!is_empty())
{
T c = lst.get_head_suffix() ;
return c ;
}
}
#endif
-- you are not the only one with this problem. Apparently when using eager-inclusion, the implementation file must be restricted.
-Alex
Note: Hopefully you are also only including your Stack.h header file and not the .cpp file with it (since its already being included via eager inclusion).
Assumed solution--
#define Class class
class Link;
class Room;
Class Space
{
//...
};
Class Room : public Space
{
Link* l;
//...
};
Class Link : public Space
{
Room* r;
//...
};
It sounds like your on to something, only I don't know what it is your saying :(
What do you mean "pull in lines from target read file and store them in a stack<string>"? You mean write a "while" statement, assigning the value of all the information in the column to a string? Wouldn't that go against the idea of using an array?
And whats a "queue"?
My apologies.
Apparently I missed the portion of your first statement "I cannot use anything else, rules are rules." Please forget my previous comment.
You may want to consider this process--
-Pull in lines from target read file and store them in a stack<string>
-pop strings from stack and write them to file
That's if the strings need to be listed in reverse order.
If you have to reverse the strings and list them the process can be done the same way except with a queue instead of a stack, and of course the queue would only store the reversed version of the string before writing to the file.
Hopefully this helps.
Same problem here. People like me cant get a job. Not even any minimum wage retail jobs going any more. I mean , i failed to get a McJob , wtf..
I expect to get 'laid off' soon also XD
Well actually I could just work full-time as a tutor for 2 different colleges. Apparently nobody wants to tutor Computer Science these days. Job security ftw! O_O
You could possibly do the same if all else fails =)
-Alex
you need to have the concept of 'object oriented programing' . A behavior(function) is belong to a object, it can not exist seprately. just like a hand can not do anything if it is not a part of a body....
Thinking in this way you 'll get the idea.
if you still want to use it in traditional way, you can not declare the function in a class.
Not quite.
You can have behavior functions via the 2nd and 3rd levels of polymorphism also.
The 3 (or maybe '4') levels of Polymorphism that I know of are-
1.) Virtual
2.) Static
3.) Callback
[4.) Delegation]
- the 4th is questionable since I've only recently heard about it and it seems to be an implementation in only a select few languages @_@.
You can have a Callback method that uses polymorphism via calling some function that meets the required signature (return, parameters, and class/nonclass info, and any other info regarding if the method is meant for const and non-const objects or just non-const objects... possibly even calling convention... possibly even the restriction of the scope of the function (though I don't think I've encountered that issue), etc). Of course the method may not have the same name as another but it will have enough similar traits to be invoked as a generalized type at run-time.
There's also Static polymorphism. This is typical with template-types where method and member lookup for …
You could also make a Menu class to encapsulate the banking operation. However, it might be better to specialize your Menu and give it a name (and make an 'abstract' base class Menu for general Menu's ).
-Alex
Most of your statements were so brilliant, I couldn't understand them!
"Shizah happens!" @_@
This is what I believe (in my honest opinion)-
The entire world is going through a recession (and soon a depression). Many companies are going to take advantage of the banks' decisions of supplying more money to their shareholders and less money to people needing loans, and also cut off on their size to ensure that their income can remain steady.
- again, this is what I believe. I have no evidence to found some of the material stated in my statement. I don't wish to argue my point with anyone elses because it would be a moot argument based on a point with little water under it. This is just something I assume would happen during a recession period where companies will panic and make 'business decisions' to remain unhurt for the duration of the depression.
=/
-Alex
Chances are likely that your Instructor wishes for both your getArms and getLegs methods to return an array of Limbs--
Arm[] getArms(){
return arms;
}
Leg[] getLegs(){
return legs;
}
-- however, something about the assignment suggests that your Human class doesn't simply hold an array of 2 arms and 2 legs, but instead a Limb array of 4 Limbs.
From there you would need to make create a Leg array and extract the instances of leg objects references from the Limb array and assign those references to the local array generated in getLegs. The same idea would hold true for getArms.
What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.
If you work in an environment similar to mine, you'll have people telling you to "GIYF!" quite a bit XD.
If there is a term you don't understand, you should definitely study it. I find it much easier to learn programming concepts after educating myself with terminology.
Not only that, but by understanding more terminology, you can come up with more meaningful definitions for words in code that you are planning to share with others that may work with you or will be the receiver of an implementation you designed when you hand off the code.
Wikipedia, Google and Dictionary are your ultimate programming friends, to say the least! O_O
It might help if you explain what your Graph-class is supposed to do.
By the way, what is your constructor definition supposed to do?
You assign numV to be 0 then you de-reference an uninitialized array of vertices.
You probably meant to do something like this--
Graph::Graph(int num) : numV(num), vertices(new VertexNode[num]){
memset (vertices, 0, sizeof(VertexNode) * num);
}
-- the numV looks like it represents the total number of VertexNodes (or vertices) and it is initialized via pre-initialization, along with your pointer to VertextNodes.
The memset in the constructor body is necessary because by calling new you are invoking the default constructor of an instance of a class ( or struct or union in C++ ) in which it is typically the responsibility of the that constructor to initialize members of the object. However, because your struct of type VertexNode has no constructor you have to explicitly set the values inside the struct. A good way of doing so is by using memset. In the above code the memset sets the bit-value of every byte for each VertexNode to zero, so everything has a value of 0 in your struct.
So this means...
struct VertexNode // Structure representing a vertex
{
string vname; // Name of vertex
bool mark; // Marked flag
EdgeNode* edgePtr; // Pointer to list of edges
};
*string's members are set to zero (the backing char-pointer a string has is likely to point to null),
as well …
Since Christmas is coming up, I suppose I'll revive this thread =)
And Christmas is nice! I always get what I want...
...a day off =P
-Alex
Also, it may be more beneficial for you to ignore a specified amount of characters or ignore characters until a specified delimiter is met--
#include <iostream>
using std::cin;
//...
int main(){
//...
cin.ignore(INT_MAX, '\n');
return 0;
}
If you put cin in an error-state, you will have to pull it out of its error-state first before attempting to ignore characters.
Speaking of pizza, it's time to order one! =)
Hmmm... let's see...
I typically only order pizza with Pepperoni, Italian Sausage and rarely will I go for Supreme @_@
What are some other fairly good toppings (for pan-crust pizzas)? =)
-Alex
What I'm saying is change the operator prototype--
// Takes a pointer to an ios that accepts an ios arg, ios_base
LogBuffer& operator<<(ios& (*fct)(ios& iosArg));
-- and definition to --
// Takes a pointer to an ios that accepts an ios arg, ios_base
LogBuffer& operator<<(ios_base& (*fct)(ios_base& iosArg));
--but only if the operations within the operator will allow you to do so. Since ios_base is a super-type of ios I'm assuming that ios_base wont have the same functionality (or the same amount of members) as ios.
In the event that you do not want to change the definition of your operator for ios-types, change your cbHandle to accept and return a reference to an ios type instead of an ios_base.
/**
* Possible definition of fib_msg_reqHeader_t before you decide to change it
*/
struct fib_msg_reqHeader_t{
//...
ios_base& (*cbHandle)(ios_base&);
//...
};
/**
* Possible definition of fib_msg_reqHeader_t after you decide to change it
*/
struct fib_msg_reqHeader_t{
//...
ios& (*cbHandle)(ios&);
//...
};
--again only do this if it wont make any major changes in other portions of code. Consider each option carefully and if you find a solution you can simply add another stream-extraction operator to handle ios_base types.
I think the problem may exist in your hf_logger.h file--
class LogBuffer
{
public:
LogBuffer(LoggerFunctor& loggerFunctor);
~LogBuffer();
uint8_t* GetStart();
size_t GetProcessedSize();
void Flush();
void SetFormat(ios::fmtflags flags, ios::fmtflags mask);
uint8_t GetIndent();
void SetIndent(uint8_t indent);
// Basic types
LogBuffer& operator<<(int8_t& data); // a character, not a number
LogBuffer& operator<<(const int8_t& data); // a character, not a number
LogBuffer& operator<<(uint8_t& data); // a character, not a number
LogBuffer& operator<<(const uint8_t& data); // a character, not a number
// C strings
LogBuffer& operator<<(const char* data);
LogBuffer& operator<<(char data[]);
// std::string
LogBuffer& operator<<(std::string& data);
LogBuffer& operator<<(const std::string& data);
// Generic flat type this function is current issue generator
template <class T>
LogBuffer& operator<<(T& data);
// Single element pointer
template <class T>
LogBuffer& operator<<(T* & data);
// Array
template <class T>
LogBuffer& operator<<(const MsgBufferArray<T>& data);
// Manipulators
// Takes a pointer to an ios that accepts an ios arg, ios_base
LogBuffer& operator<<(ios& (*fct)(ios& iosArg));
};
template <class T>
void trace(HF_OLogBuffer& msgBuffer, T& data)
{
data.trace(msgBuffer);
}// this is the function call from which we got an error i.e. {request for member 'trace' in 'data', which is of non-class type 'std::ios_base& ()(std::ios_base&)'}
inline
void trace(HF_OLogBuffer& msgBuffer, HF_int8_t& data)
{
msgBuffer << data;
}//and so on trace functions definitions..
Because you only have a 'specialization' for an ios type (and anything derived from it) and not its super type, you're generalized function is invoked instead of the one you most likely intended to be invoked.
That's my assumption, given the error generated. I only know so …
Reflection is a very specialized solution, much like the Java Native Interface, Remote-Method Invocation, Wildcards, Design Patterns, transient values, volatile values, concurrency, etc.
Don't expect simple solutions for something that is seemingly "simple."
I tried to remake the program and provide examples in an attempt to reproduce the problem on Microsoft Visual C++ 2005/2008 compiler, but I different errors than the one I expected despite the tests--
/**
* Assumed header file for LogBuffer
*/
#ifndef LOGBUFFER_H
#define LOGBUFFER_H
#include <iostream>
/* Dummy values */
typedef char LogFactor;
typedef int uint8_t;
template<class T>class MsgBufferArray;
typedef char LoggerFunctor;
typedef char ostringstream;
using std::ios;
namespace Log{
class LogBuffer;
template <class T>
void trace(LogBuffer& msgBuffer, T& data);
class LogBuffer{
public:
LogBuffer(LogFactor& logFactor);
~LogBuffer();
uint8_t* GetStart();
size_t GetProcessedSize();
void Flush();
void SetFormat(ios::fmtflags flags, ios::fmtflags mask);
uint8_t GetIndent();
void SetIndent(uint8_t indent);
// Generic flat type
template <class T>
LogBuffer& operator<<(T& data);
// Single element pointer
template <class T>
LogBuffer& operator<<(T* & data);
// Array
template <class T>
LogBuffer& operator<<(const MsgBufferArray<T>& data);
protected:
void SetDefaultFormat();
//LoggerFunctor& _functor;
ostringstream _buffer;
uint8_t _indent;
};
}
#include "LogBuffer.cpp"
#endif
/**
* Assumed implementation file of LogBuffer
*/
#ifdef LOGBUFFER_H
using namespace Log;
LogBuffer::LogBuffer(LogFactor& logFactor){}
LogBuffer::~LogBuffer(){}
template <class T>
LogBuffer& LogBuffer::operator<<(T & data){
::trace(*this, data); // trace fuction called here
return *this;
}
template <class T>
void trace(LogBuffer& msgBuffer, T& data){
data.trace(msgBuffer);
}
#endif
/**
* Driver program for testing--
*/
#include <iostream>
#include "LogBuffer.h"
using std::cout;
using std::cin;
using std::endl;
class Tracer{
public:
Tracer(){}
void trace(LogBuffer& msgBuffer){
cout << "Trace successful" << endl;
}
};
class NonTracer{
public:
NonTracer(){}
char trace;
};
int main(){
char refChar = '\0'; // dummy variable
Tracer myTracer; …
why try to figure out how to fly, if you can walk? just use two for loops as javaAddict suggested
Because some people receive inspiration to be a programmer by seeing all of the angles instead of just one.
Please use code-tags and proper indentation.
I believe you meant to close your while loop and your run method before overriding paint--
import java.awt.*;
import java.applet.*;
/* Part 0, CSC104 Assignment 2 Fall 08
* Where is Wall-e? */
public class Part5 extends Applet implements Runnable{
private Location ovalOffset;
private Location pictureLocation;
private Color color;
private Oval oval;
private Size size;
private Location ovalOffset2;
private Color color2;
private Oval oval2;
private Size size2;
private Box neck;
private Location neckOffset;
private Color neckColor;
private Size neckSize;
private Square bot;
private Location botOffset;
private Color botColor;
private Size botSize;
private Oval eye;
private Location eyeOffset;
private Color eyeColor;
private Size eyeSize;
private Oval eyes;
private Location eyesOffset;
private Color eyesColor;
private Size eyesSize;
private Oval wheel;
private Location wheelOffset;
private Color wheelColor;
private Size wheelSize;
private Oval wheels;
private Location wheelsOffset;
private Color wheelsColor;
private Size wheelsSize;
int x=20;
int y=10;
Thread appletThread;
/* Initialize variables for an oval. */
public void init() {
pictureLocation = new Location(0, 0);
ovalOffset = new Location(0, 0);
color = new Color(0, 0, 0);
size = new Size(100, 200);
oval = new Oval(pictureLocation, ovalOffset, size, color);
ovalOffset2 = new Location(10,10);
color2 = new Color(255, 255, 255);
size2 = new Size(80, 180);
oval2 = new Oval(pictureLocation, ovalOffset2, size2, color2);
neckOffset = new Location(87, 100);
neckColor = new Color(0, 102, 92);
neckSize = new Size(115, 22);
neck = new Box(pictureLocation, neckOffset, neckSize, neckColor);
botOffset = new Location(0, 200);
botColor = new Color(181, 84, 0);
botSize = …
Why not just create your own implementation of FTP by using Sockets and sending a collection of bytes from one application to another then have the receiving application write those bytes to a File (or FileDescriptor object if that is possible).
Edit: Here's an Open-Source API that seems promising - Linkage
Check out the stickies in this forum. You should get a lot of good references from them.
-Alex
You can probably get away with using one method, recursively until it resolves to an absolute base case.
I'm sure you can because I remember someone asking this same exact question, except they had to use recursion. They eventually found a solution.
Ah! After bending my mind trying to migrate code from one language to another, I completely overlooked this.
Thanks! =)
Bah nevermind, I'll keep it as it is. Thanks for confirming the precedence of modulus!
Now I'm curious...
When would it ever matter if you multiplied before dividing or subtract before adding?
Multiplication and division are technically the same.
Your expression 2 / 5 * 9 is the same as 2 * .2 * 9 so why in the world would it matter if you multiplied first instead of dividing?
Maybe it's because you're using int division?
The same argument exists for subtracting and adding. 2 - 5 + 9 is the same as 2 + -5 + 9 which will yield the same results despite whether you add or subtract first.
Are you using unsigned types?
And if modulus has equal precedence then I suppose my program is technically correct, but I would like it to have either stronger or weaker precedence before MD or after MD.
And Vernon I know you are the mathy-type so I am looking over your post carefully, trying to understand what you mean when you say I need a third option (i.e. Modulus before Division but after Multiplication), when M and D are technically the same?
-Alex
I remade an equation-solver program from Java to C++, and I plan to post it soon but I would rather not until I can determine where modulus fits in with PEMDAS.
To those who don't know, PEMDAS is the order in which mathematical expressions are to be evaluated. The order is
-Paranthesis'
-Exponents
-Mulitplication and Division (same level)
-Addition and Substraction (same level)
so if I have an expression 2 + 3 * 5, according to PEMDAS, 3 * 5 must resolve first so the expression becomes 2 + 15, and the answer afterwards is 17.
Now my problem is that I don't know where Modulus fits in with PEMDAS.
Does it have higher or lower precedence than Multiplication/Division?
8 * 9 % 5 --- what should happen first? 8 * 9 or 9 % 5?
It matters because 8 * 9 first yields 72, and 72 % 5 yields 2 (because 5 subtracts into 72 fourteen times, but cannot subtract into 2 wholly, so 2 is the remainder).
If 9%5 occurs first, 4 is the result for that minor expression and 8 * 4 is 32 so the operator precedence does indeed matter.
I've done some looking up on Google and couldn't find an article to resolve this issue.
Here's my program as it is now--
/**
* Numerics.cpp
*/
#ifndef NUMERICS
#define NUMERICS
#include <sstream>
#include <string>
using std::stringstream;
using std::string;
/**
* Convenience …
Is there any way that I can take a String and somehow use it as if its the name of one of my declared Objects? For example, if I have an Animal named germanShephard, is there some way I could say String gerSh = "germanShephard"; and then treat gerSh as if it was the equivalent of saying germanShephard in my program?
Dictionary is also an okay way to go, but I believe it is a deprecated API (or incredibly outdated).
Edit: Actually, you can probably get away with using a Pair<K, V> instead of something that handles an entire collection.
I'm not sure where it is defined in the Java Standard Library, but if all else fails you can easily create your own pair class.
Yup, I edited my post a minute before you posted this.
Hey, hey! I've already given you a +1 on rep!
Enough! >_<
=P
Beat you to it. :)
Yeah, but I forgot one thing.
IOException is a superclass of EOFException so its possible that the EOFException did occur.
Actually, if you read the documentation of DataInputStream's method readChar, you'll notice that it attempts to read not one, but 2 bytes--
-- but instead of throwing and EOF error you're getting a IOException, which seems confusing.
My guess is that there's only the character 'i' (1 byte of information) in DataInputStream and the EndOfFile Character is not returned and therefore an exception is thrown because there aren't 2 bytes to read, but only 1.
Edit: Yes, this seems to be the case because I ran the test with two i's next to each other instead of one, and the character ? was returned and no exceptions were thrown.
Have you tried providing a .txt extension in the String name of test?
// Open an input stream
stream = new FileInputStream ("test.txt");