Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007
    Posts
    198

    istream doesn't work

    Compiles and runs Okay.
    However, I input the variables at the console and it displays the same x,y,z that I defined in the //Create Entities @ Location.

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    //Classes
    
    	class Point
    	{
    	public:	
    		Point (float f_x = 1.0, float f_y = 1.0, float f_z = 1.0);
    		~Point();
    
    		//set
    			void setX(float X);
    			void setY(float Y);
    			void setZ(float Z);
    
    			void setXYZ(float X, float Y, float Z);
    		//get
    			float getX();
    			float getY();
    			float getZ();
    
    			void getXYZ(float &X, float &Y, float &Z);
    
    	private:
    		float x, y, z;
    
    	protected:
    	};
    
    	//Class::Point
    
    		Point::Point (float f_x, float f_y, float f_z)
    		{
    			cout << "//Constructor \n\nWe're in the constructor with arguements!\n\n\n\n";
    			x = f_x;
    			y = f_y;
    			z = f_z;
    		}
    
    		Point::~Point()
    		{
    			cout << "//Destructor \n\nWe are in the destructor...\n\n\n\n";
    		}
    
    		//Point::set
    
    				void Point::setXYZ(float X, float Y, float Z)
    				{
    					float setX(X);
    					float setY(Y);
    					float setZ(Z);
    
    
    					/*
    					x = X;
    					y = Y;
    					z = Z;
    					*/				
    				}
    
    					void Point::setX (float X)
    					{
    						X = x;
    					}
    					void Point::setY (float Y)
    					{
    						y = Y;
    					}
    					void Point::setZ (float Z)
    					{
    						z = Z;
    					}
    
    
    			//Point::get
    			
    				float Point::getX ()
    				{
    					return x;
    				}
    
    				float Point::getY ()
    				{
    					return y;
    				}
    
    				float Point::getZ ()
    				{
    					return z;
    				}
    
    				void Point::getXYZ(float &X, float &Y, float &Z)
    				{ 
    					X = getX();
    					Y = getY();
    					Z = getZ();
    				}
    		
    	
    	ostream &operator <<(ostream &stream, Point &p)
    	{
    		stream << p.getX() << " " << p.getY() << " " << p.getZ();
    		return stream;
    	}
    
    	istream &operator >>(istream &stream, Point &p)
    	{
    		float x, y, z;
    		stream >> x >> y >> z;
    		p.setXYZ(x, y, z);
    
    		return stream;
    	}
    	
    
    int main()
    
    {
    	//Create Entities @ Location
    		Point myLocation(23, 53, 32);
    		Point mRatLoc(0,  1,  1);
    	//Displays Entity's Location
    		cout << "\tMyLocation is at: "<<(myLocation) << endl;
    		cout << "\tmRatLoc is at: " << (mRatLoc) << "\n\n\n\n";
    
    	//Change the Location of Entities
    		cin >> myLocation;
    		cout << "\n\n\n\n";
    		cout << "myLocation is: "<<(myLocation)<< "\n\n\n\n";;
    
    	//Stops the Console from Ending Immediately		
    		cin.get();
    
    		return 0;
    }
    Last edited by KeithGarry; 12-20-2008 at 12:59 AM.

  2. #2
    Join Date
    Dec 2007
    Posts
    198
    Ahhh...

    float setX(X);
    float setY(Y);
    float setZ(Z);
    float is a fail.

    I removed them and all is well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •