Thread: need help!!!

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Post need help!!!

    i have an assigment i should read the integers from the file and create an object for each line to store the integer(each line has 3 integers)
    Code:
    #include <iostream.h>
    #include <fstream.h>
    
    class Line {
    		private:
    			int value[3];
    		public:
    			void set_value(int _new,int index)  { value[index] = _new; }
    	        int get_data() {return value[2];}
    			Line *next;
    };
    
    int main()
    {
    	 int object = 0;
    	 int temp;
    	 Line *line,*newLine,*currentline_address;
    	 ifstream ptr("d:\\tc\\bin\\source.txt",ios::out);
    	 if(!ptr)
    	 {
    		 cerr << "source.txt could not be open\n";
    		 //exit(0);
    	 }
    	 else
    	 {
    		 while(!ptr.eof())
    		 {
    			  if(object == 0)
    			  {
    				  line = new Line;
    			for(int i = 0;i < 3; i++)
    			{
    						ptr >> temp;
    		  line->set_value(temp,i);
    			}
    			currentline_address = line->next;
    			object++;
    		}
    		else
    		{
    			newLine = new Line;
    			newLine = currentline_address;
    
    			for(int i = 0;i < 3;i++)
    			{
    				ptr >> temp;
    				newLine->set_value(temp,i);
    			}
    
    			currentline_address = newLine->next;
    		}
    		 }
    	 }
    	 cout <<line->get_data();
    	 return 0;
    }
    whats wrong??
    the output is an address

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    38
    you are outputting a address? hmm what uses addresses? Think about this if you can't figure it out look back at pointers and such.

Popular pages Recent additions subscribe to a feed