I've a file ashii with a sequence of 65536 zeros and ones (that should represent a binary image). I have to put it in a int[256][256] array so i will be able to analyse it with morphological filters. Unluckyly at my university nobody explained us how to read a file, so i just googled for the solution. Now, every time i try to image=fopen(filename,r) and i "cout<<image;" as result I get only a (very short) alphanumeric sequence.
I tried the command (int)image; but it just transforn the aplhanumeric sequence in a numeric sequence.. So, no way to read a "0" or "1" from a file containing only zeros and ones. I need that shortly for my thesis (image analysis).
i googles "ios.get()" and "c++ ios.get()" and i received no answers. Could you please be more specific?
I'm a mathematic students, i've a decent understanding about logic and algoritm but not so much knowledge.
#include <fstream>
#include <vector>
usingnamespace std;
int main(){
vector<char> fromFile; // to store all the chars from the file.
fstream file;
file.open("myFile.txt",ios::in);
char buf = file.get(); // get a single char from the file, and store it in buf
while(!file.eof){ // loop until we hit the end of file
fromFile.push_back(buf); // add buf to our vector (dynamic array basically)
buf = file.get(); //get the next letter from the file
}
//you now have the whole file, stored char by char in fromFile.
}