3

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

user2136754
  • 107
  • 1
  • 3
  • 9

2 Answers2

4
std::ifstream in("Path\\To\\File.txt");
std::string line;
while (std::getline(in, line))
{
    if (i++ == 13)
    {
        break;
    }
}
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
2

Assuming in is a file stream

#include <sstream>
#include <string>    
while (std::getline(in, line))
{

       // Do your thing 
}