This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]