Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ hasNextLine

I have something done very easily in Java, but what is the C++ version of the following:

while (in.hasNextLine())
{                
     String line = in.nextLine();

     if (i == 13)
     {
         i++;
         break;                    
     }  

     i++;
}

It's the nextLine parts I can't seem to find a C++ equivalent for

like image 688
user2136754 Avatar asked Jun 18 '26 02:06

user2136754


1 Answers

std::ifstream in("Path\\To\\File.txt");
std::string line;
while (std::getline(in, line))
{
    if (i++ == 13)
    {
        break;
    }
}
like image 160
Billy ONeal Avatar answered Jun 19 '26 17:06

Billy ONeal