-3
Text.txt 
Hi how 
are you 
Hey 
There

char* strings;

How do I dynamically allocate enough data for strings and properly and copy it into memory?

1 Answers1

0

Use std::string. It will handle the allocation for you.

Paul Belanger
  • 2,354
  • 14
  • 23
  • Practicing a lab at the moment for char * specifically. Is there a difference? Sorry, I'm still learning slowly. – TheNubProgrammer Sep 17 '17 at 00:19
  • @TheNubProgrammer: [A pretty huge difference](https://stackoverflow.com/questions/1287306/difference-between-string-and-char-types-in-c). – Jamal Sep 17 '17 at 00:36
  • @Jamal Do you know of any methods that i could do to dynamically allocate data for a char* by counting each line in the text file? – TheNubProgrammer Sep 17 '17 at 00:43
  • @TheNubProgrammer: using `char*` is for C. In C++, you should be using `std::string` instead. Coupled with `std::ifstream`, `std::getline()` and `std::vector`, all of the file I/O and memory management would be done for you. If you are learning C++, learn C++ properly, not C. – Remy Lebeau Sep 17 '17 at 07:47