Неправильно выводится массив char

файл консоль

#include <iostream>
#include <Windows.h>
#include <fstream>
using namespace std;

int main()
{
    setlocale(LC_ALL, "Russian");
    ifstream file;
    file.open("tekst.txt");
    if (!file)
    {
        cout << "Error! File is not open";
        exit(4);
    }
    char A, * STR1, * STR2;
    int flag = 0, str1 = 0, str2 = 0;
    while (!file.eof())
    {
        file.get(A);
        if (flag == 0) { str1++; }
        else { str2++; }
        if (A == '\n') { flag = 1; }
    }
    file.close();
    //
    cout << str1 << " " << str2 << endl;
    //
    STR1 = new char[str1];
    STR2 = new char[str2];
    flag = 0;
    ifstream file2;
    file2.open("tekst.txt");
    for (int i = 0; i < str1 - 1; i++) file2.get(STR1[i]);
    STR1[str1 - 1] = '\n';
    file2.get(A);
    for (int i = 0; i < str2 - 1; i++) file2.get(STR2[i]);
    STR2[str2 - 1] = '\n';
    cout << STR1 << endl << STR2;
    file2.close();
    delete[] STR1;
    delete[] STR2;
    return 0;
}

Ответы (0 шт):