Hi... I'm very excited to post a question, since I always do everything by myself.
I'm reading several lines from a text file using istream::getline(char *, streamsize n). I get the file name from the command line. Here is the code:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main ( int argc, char *argv[])
{
char *line = new char;
ifstream in (*++argv);
if ( in.is_open() )
{
while ( in.good() )
{
in.getline (line, 1000);
cout << "line:\n" << line << "\n\n";
}
in.close();
}
return 0;
}
Then I get segmentation fault right when at the end of the file.
Strange thing is that i swap the lines:
char *line = new char;
ifstream in (*++argv);
And everything works fine.
Using GCC 4.4.5 on Ubuntu 32bit
Btw: I know assembly language and know what a segmentation fault is