I'm trying to take data from a file stream and put it into a char*. (I know using strings is better.. but I'm kind of being forced to do so). And so I have the code below almost working like it should, but I get two extra characters at the end. How can I fix that?
I'm not really concerned about losing spaces, since in the end I just need the letters of the alphabet for something I would do later.Code:#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 = new char[]; int i = 0; while(!dataFile.eof()) { dataFile >> str[i]; i++; } std::cout << str; return 0 }