This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Fgets is not working on linux/gcc3.2.1
- From: John Love-Jensen <eljay at adobe dot com>
- To: Ajay Bansal <Ajay_Bansal at infosys dot com>, <redhat-devel-list at redhat dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 10 Apr 2003 07:26:02 -0500
- Subject: Re: Fgets is not working on linux/gcc3.2.1
Hi Ajay,
Why not do it C++ style, instead of co-mingling C and C++ styles?
Sincerely,
--Eljay
PS: your data-type Hungarian notation is incorrect. I strongly suggest
that you avoid date-type Hungarian notation, unless you are going to be
meticulously accurate. (Otherwise it contributes to code obfuscation.)
PPS: I also recommend on "using" the particular item in the other
namespace, instead of pulling in the whole namespace.
PPPS: I also recommend using C++ headers, instead of pulling in C headers
into your C++ code. (i.e., <cerrno> and <cstdlib>.)
---------------------
#include <iostream>
using std::cout;
using std::endl;
#include <fstream>
using std::
#include <string>
using std::string;
// #include <cerrno> -- not needed.
// #include <cstdlib> -- not needed.
int main()
{
string fileName("/tmp/log.txt");
string line;
ifstream file(fileName.c_str());
int lineNumber = 0;
while (getline(file, line)) {
++lineNumber;
cout << "Line " << lineNumber << " read is : " << line << endl;
}
return 0;
}