How do I use get() with arrays? I've looked at the article on the forums, but it isn't much help on what I want to do. I know I'm using get correctly, but the pointer isn't moving up in the array.
Meaning that when I read from the text file, the character that gets read is given to pointer and then to buffer. The next character read REPLACES the original character. What I want is that the next character gets placed in the next variable in the array.
I'm not sure where I went wrong, but it might be at the pointers?
#include <iostream>
#include <fstream>
#include <istream>
#include <string>
usingnamespace std;
void main (void){
char buffer[61];
char *pointer;
pointer = buffer; //points pointer to buffer
ifstream Maps;
Maps.open ("Map01.txt",ios::in); //open file
if(!Maps){ //check if file is open
cout<< "error";
}
while (!(Maps.eof())){ //until end of file
Maps.get(*pointer); //Retrieve character value and give it to pointer, which then points it to buffer.
}
for (int i=0;i<60;i++){ //cout buffer.
cout<<buffer[i];
}
system("pause");
}
There are several member functions get in class std::basic_istream. You use the function that reads only one character from the stream and places it in the first element of array buffer. So every next read overwrites already read character.
I don't understand this part of your code. What does && maps do? I thought maps was the "variable" we gave to the stream? I understand the N-1 part, not the && Maps.