Can someone tell me how do we read the first line in a text file?
As far as I know,the code below will read the number of line that are present in the text file. But how do I alter this code so that I can only read the first line in the text file.
while (is.good())
{
c=is.get();
if(c=='\n')
num++;
}
is.close();
}
No. You should strive to understand the pieces of code you copy and paste from God-knows-where.
The C++ reference on this site (or rather, Google) will help you with that. As will a good book.
Right..... Then can you suggest me which book should I look into? I'm interested in buying one.
I understand how does the above code work. I am just clueless on where should I put the getline thing as I am really new in this C++. And I also don't really understand what does getline do.