0

Im having a hard time understanding how to read the first line of a file. im trying to read the 1st line of a file and then check to see if its blank. this is what i came up with but still not working

void buildTree( NodePtr &root, ifstream& input )
    {
        char line [50];
        line= input.getline();

        if ( line ==  NULL )
        {
           root = NULL;
           return;
        }

    }
4

2 回答 2

2
void buildTree( NodePtr &root, ifstream& input )
    {
        char line [50];
        input.getline(line, sizeof line);

        if (strlen(line) == 0)
        {
           root = NULL;
           return;
        }

    }
于 2013-04-30T00:14:47.640 回答
0

我认为你做错了 getline() 的格式如下。

如果您使用的是 char 数组:

char buffer[256];
input.getline(buffer, 256);

如果您使用的是字符串:

string buffer;
getline(input, buffer);
于 2013-04-30T00:16:46.273 回答