I have the following program
ifstream input;
input.open("File.txt",ios::in);
while(input){
char arr[30];
input.get(arr,30);
cout << arr;
}
My file is
A 100
B 200
However, my output has only the first line, that is A 100
. When I replace .get
with .getline
it works as expected.
I did some searching and found that .get
keeps the \n
in the stream, while .getline
removes it altogether.
Is that the reason why I'm getting only the first line? If it is, how do I fix it?