I have a file in which I have the maximum length of the string on the first line and the string itself on the second line.
It is an educational task so I can't use the <string>
library.
I did this:
ifstream input;
input.open("input.txt");
int n;
input >> n;
char* str = new char[n];
input.getline(str, n); // This is the thing i want to get rid of.
input.getline(str, n);
And it works, but I have to call getline()
twice, because after I get the length with input >> n;
there is still a '\n'
char after it on that line, and to go to the second line of the file I have to call getline()
, that is the only solution that I came up with. Any help will be much appreciated!