I am attempting to convert text from a text document to a char array. To begin I tried to implement a dynamic array. However, for some reason when I attempt to save each char from the text into the new array it returns a bunch of equals signs. Down below is what I have:
Say for example the text said something like "Make this a char array".
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char x;
int y = 0;
ifstream file;
file.open("text.txt");
while (file >> x)
y++;
char *phrase = NULL;
phrase = new char[y];
for (int i = 0; file >> x; i++)
{
phrase[i] = x;
}
for (int i = 0; i < y; i++)
{
cout << phrase[i];
}
}
It will end up outputting: "=================="
I did research on this issue but I couldn't find anything that clears it up.