Re: Fgets is not working on linux/gcc3.2.1
John Love-Jensen <[email protected]>
| Newsgroups | gmane.comp.gcc.help,gmane.linux.redhat.devel |
|---|---|
| Message-ID | <BABACD0A.81BD%[email protected]> |
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;
}