Read only one line in SD card I have some C++ code, but I cant convert it to Arduino language.
I just want to ask, what is the same as getline() (C++ code) function in Arduino?

I just wanted to get the first line in my SD card...
I can only display all text inside my SD card...

Example:

line1   &lt;-   only this line should display(and this line will delete in text 
             file... but that is another issue... i will just focus to get the 
             line1 and get the value)

line2

line3

line4

line5


This code displays all lines

    #include &lt;SPI.h&gt;
    #include &lt;SD.h&gt;

    File myFile;

    void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port                          only
       }


       Serial.print("Initializing SD card...");

       if (!SD.begin(4)) {
         Serial.println("initialization failed!");
         while (1);
       }
       Serial.println("initialization done.");

       // open the file. note that only one file can be open at a time,
       // so you have to close this one before opening another.
       myFile = SD.open("test.txt", FILE_WRITE);

       // re-open the file for reading:
       myFile = SD.open("test.txt");
       if (myFile) {
         Serial.println("test.txt:");

         // read from the file until there's nothing else in it:
         while (myFile.available()) {
           Serial.write(myFile.read());
         }
         // close the file:
         myFile.close();
       } else {
         // if the file didn't open, print an error:
         Serial.println("error opening test.txt");
       }
     }

     void loop() {
       // nothing happens after setup
     }
There is no builtin way to do that but you got all the necessary tools at hand.

End of line should be signaled by a decimal 10, aka LF(Line Feed) character.
So what you do is keep reading until you encounter LF or end of file, which then is the entire line you want to read. 

while (file.available() &amp;&amp; file.peek() != 10) // peek returns the next character without incrementing the read index
    file.read();


This code does exactly that. Now you could either store the read bytes in a buffer (big enough!) right away or instead find out the number of bytes beforehand to create a precisely sized buffer afterwards and use the read(buffer, length) overload to read all bytes at once.

Please keep in mind that the LF character has to be there in order to be read. So if you are the one creating the files, be sure to place it. (most desktop text editors do that for you)

Example:

char buffer[20];
uint8_t i = 0;

while (file.available() &amp;&amp; file.peek() != '\n' &amp;&amp; i &lt; 19)    // note how this also prevents the buffer from overflowing (18 max to leave space for '\0'!)
{
    buffer[i] = file.read();
    i++;
}
buffer[i + 1] = '\0';    // it is good practice to end strings with a terminating NULL character