J
JoeC
I am trying to write a graphic library. Yes, I know that it is byoined
the scope of this group but I broke the file down to reading a text
file of numbers. The problem I am having is that the program is not
printing the same numbers that are in the file
Here is my code:
#include<windows.h>
#include<iostream>
#include<fstream>
using namespace std;
int main(){
int ud, lr; // Dimentions of the graphic
ifstream fin("graphic.txt");
int gr[128]; //holds values for the bitmap inprogram is BYTE but int
will do
int * pgr = &gr[0]; //rnd access iterator to the array
int ix = 0; //if I want to use an index
if (fin){ // reads file provided there is more to read
fin>>ud>>lr; // reads the dims of the graphic this is ok
while(fin){ //fills the array
fin>>*pgr; //reads the array with a rnd access iterator (realy
a pointer)
pgr++; //advances the pointer
}
} else {
cout<<"could not open file"<<endl;//if the file dosn't open
}
cout<<ud<<endl;//show height works
cout<<lr<<endl;//shows witdth works
pgr = &gr[0]; //reste the pointer to the beginning of the array
for(int lp = 0; lp < 16; lp++){ //just a loop to cycle thought the
array
cout<<*pgr<<endl;//prints the values of the array
//These values are different than what is in the file.
pgr++; //advances the pointer
}
system("pause"); //admin
return 0; //you should know what this is.
}
Here is my txt file graphic.txt
16 16
0 0 255 255 0 0 255 255 0 0 255 0 255 0 0 255
This code is similar that I posted but I remove all the graphic
refrence for my experimentation and learning. I think the problem has
something to do with how I am using the pointers.
the scope of this group but I broke the file down to reading a text
file of numbers. The problem I am having is that the program is not
printing the same numbers that are in the file
Here is my code:
#include<windows.h>
#include<iostream>
#include<fstream>
using namespace std;
int main(){
int ud, lr; // Dimentions of the graphic
ifstream fin("graphic.txt");
int gr[128]; //holds values for the bitmap inprogram is BYTE but int
will do
int * pgr = &gr[0]; //rnd access iterator to the array
int ix = 0; //if I want to use an index
if (fin){ // reads file provided there is more to read
fin>>ud>>lr; // reads the dims of the graphic this is ok
while(fin){ //fills the array
fin>>*pgr; //reads the array with a rnd access iterator (realy
a pointer)
pgr++; //advances the pointer
}
} else {
cout<<"could not open file"<<endl;//if the file dosn't open
}
cout<<ud<<endl;//show height works
cout<<lr<<endl;//shows witdth works
pgr = &gr[0]; //reste the pointer to the beginning of the array
for(int lp = 0; lp < 16; lp++){ //just a loop to cycle thought the
array
cout<<*pgr<<endl;//prints the values of the array
//These values are different than what is in the file.
pgr++; //advances the pointer
}
system("pause"); //admin
return 0; //you should know what this is.
}
Here is my txt file graphic.txt
16 16
0 0 255 255 0 0 255 255 0 0 255 0 255 0 0 255
This code is similar that I posted but I remove all the graphic
refrence for my experimentation and learning. I think the problem has
something to do with how I am using the pointers.