How to dynamically allocate memory to an array to read n characters from a file? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to dynamically allocate memory to an array to read n characters from a file?

Let's say I have the following: #include <iostream> #include <fstream> int size; char *charArray = nullptr; ifstream fin.open("strings.txt"); // More code... delete [] charArray; charArray = nullptr; How would I dynamically allocate memory to the array so that it could store any number of characters from a file, regardless of the file size? For example, if the file is 50 bytes how would I set int size to 50?

7th Oct 2017, 5:48 PM
RUB1C0N
1 Resposta
0
Thanks for your answer @kurwius. it helped to point me in the right direction for what I needed. šŸ‘
9th Oct 2017, 4:53 AM
RUB1C0N