Hello everyone. I am trying to copy data from a file stream into a char*. I know there are ways to do it with std::string and getline, but I have an assignment where I have to have a class that will take a char* into one of its constructors (which will represent the data in the file), hence forcing me to not use strings.
And so, my question really is how do I get file stream data and put it into a char*? I've attempted to do this with the code below, but the program keeps crashing. What is the best way to go about doing this? I know strings are recommended.. but I really have no choice in this case. I've looked at several text books, online tutorials, google, but to no avail, everyone uses strings.
#include <iostream>
#include <fstream>
#include <cstring>
int main()
{
std::ifstream dataFile("strings.txt"); // strings.txt contains "this is my string" or w/e
char* str;
while(!dataFile.eof())
{
dataFile >> str;
}
std::cout << str;
return 0;
}