- #1
GregA
- 210
- 0
I'm currently playing around with strings and char arrays and having problems initialising a char array properly. Basically I've got a text file whose length I want to check before putting the contents into a char array
I define my ifstream variable as in_data and a string as str1.
Then opening some small text file on my computer I use getline(in_data, str1)
I then initialise const int strlen = str1.length()
Now if I initialise char instuff[strlen] I get a problem saying I've initialised my array with a variable. Of course if I put a number in there directly I'm fine but surely I've already defined instuff to be constant (whatever value strlen took) and am scratching my head as to why I'm having a problem.
I apologise for the poor variable names (I'm just experimenting at the mo), and for not putting the entire program here (it is on a computer that isn't online)
Can anyone help?
I define my ifstream variable as in_data and a string as str1.
Then opening some small text file on my computer I use getline(in_data, str1)
I then initialise const int strlen = str1.length()
Now if I initialise char instuff[strlen] I get a problem saying I've initialised my array with a variable. Of course if I put a number in there directly I'm fine but surely I've already defined instuff to be constant (whatever value strlen took) and am scratching my head as to why I'm having a problem.
I apologise for the poor variable names (I'm just experimenting at the mo), and for not putting the entire program here (it is on a computer that isn't online)
Can anyone help?
Last edited: