vicky.txt file
I was born in Hupari.
Code -1
#include <iostream>
#include<fstream>
int main()
{
char ch;
std::ifstream fin;
fin.open("vicky.txt", std::ios::in);
while (!fin.eof())
{
fin.get(ch);
std::cout<<ch;
}
fin.close();
return 0;
}
Output
I was born in Hupari..
Code -2
#include <iostream>
#include<fstream>
int main()
{
char ch;
std::ifstream fin;
fin.open("vicky.txt", std::ios::in);
while (!fin.eof())
{
ch=fin.get();
std::cout<<ch;
}
fin.close();
return 0;
}
Output
I was born in Hupari.
Why while using fin.get(ch)
it reads last character twice. On other hand ch=fin.get()
reads correctly means reads last character one time only.
By the way also tell return type of fin.get(ch)
? and return type of fin.get()
is char
right ?