Need help with fstream

This is a discussion on Need help with fstream within the C++ Programming forums, part of the General Programming Boards category; Hi, having trouble getting this to work with a .raw file... When the texture is mapped it displays the image ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    1

    Need help with fstream

    Hi, having trouble getting this to work with a .raw file...
    When the texture is mapped it displays the image all in black.
    Can someone please give me a hint as to what im doing wrong?

    This is the image reading function:

    Code:
    //some previous declarations:
    //typedef 	GLubyte pixel;
    //pixel image[MAXROW][MAXCOL][3];
    //int charin;
    //int r,c;
    //ifstream in;
    
    void InputImage(void)
    {
    	printf("Enter the name of the input file: ");
    	gets(inf_name);
    
    	in.open(inf_name,ios::binary);
        
    	if(in.fail())  /* open failed */
            {
             puts("*** Can't open input file - please check file name typed!\n ");
             charin = getchar();
             exit(1);
            }
    
      	for ( r = 0;  r < MAXROW; r++ )
          	       for ( c = 0;  c < MAXCOL; c++)  {
    			if(in.eof()) {
    				
    			    printf("*** End of file reached!\n ");
    			    in.close();    /* close input file  */
    			    charin = getchar();
    			    exit(1);
    			}
    			else {
    			
    			    in >> charin;
    			    image[r][c][0] = image[r][c][1] = image[r][c][2] = charin;
    			}
                    }
    	in.close();    /* close input file  */
    	printf("\nImage input completed!\n");
     }	/* end InputImage */
    Any help would be great, thanks.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    You need to read and write using the read and write functions in fstream since you are working with binary data. The operator>> does formatted input and skips over whitespace.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 09:19 PM
  2. Fstream. I/O
    By kevinawad in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2008, 09:19 AM
  3. ARGH! fstream errors
    By OttoDestruct in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:37 PM
  4. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 11:21 AM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21