I am pretty novice at C++. Basically what I am trying to do is to read a file into any array and display it, but what happens is that a garbage values appears when running the code below. What exactly I am missing?
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
void main() {
    int array_size = 1024;
    char*array = new char[array_size];
    int position = 0;
    ifstream fin("Map.txt");
    if (fin.is_open()) {
        while (!fin.eof() && position < array_size) {
            fin.get(array[position]);
            position++;
        }
        array[position - 1] = '\0';
        cout << "Displaying array......" << endl << endl;
        for (int i = 0; array[i] != '0'; i++) {
            cout << array[i];
        }
    } else {
        cout << "File could not be opened" << endl;
    }
}
 
     
    