I Have a project for my c++ class where i need to be able to read the contents of a file and set up a dynamic array the size of that string. The above code is just me trying this strlen() out. Should I use an array?
I am doing a cash register project, selling 3 items. I save the number in stock of all 3 items to a file as well as the total sales. all 4 are of float type.
An example of the text file looks like this when opened:
10
20
30
50
I need to read these 4 values in and set up a dynamic array for them.
I have the program working fully without using the dynamic array, Its part of the assignment tough to read in from the file and set up a dynamic array for the size if what's in the file. I am very new to C++ , so I am not sure what you mean when you mention vector.
Ah, so the 'length' you are after is a count of how many lines the file contains.
Indeed, the use of a vector (which is basically an array which can dynamically resize itself as required) sounds like the answer. http://www.cplusplus.com/reference/vector/vector/