Getline () C/C ++ differences

Source: Internet
Author: User

C ++ prototype (Win32 and Linux ):

#include <iostream>istream& getline ( istream &is , string &str , char delim );istream& getline ( istream& , string& );


Processing the terminator (the default line break is used as the terminator)
After the terminator delim is encountered, delim is discarded and not stored in Str. In the next read operation, the next character of delim is read.

Test code:

#include <iostream>#include <string>int read_line(void){    std::string buf;    getline(std::cin, buf);    std::cout << buf;    return 0;    }

C prototype (Linux ):

#include <stdio.h>ssize_t getline(char **lineptr, size_t *n, FILE *stream);

Test code:

#include <stdio.h>int read_line_c(void){    char buffer[100];    getline(buffer, sizeof(buffer), stdin);    printf(buffer);}


Getline () reads an entire line from stream, storing the address of
Buffer containing the text into * lineptr. The buffer is null-terminated and contains des the newline character, if one was found.
Used to read a line of character until the line break, including the line break

Related functions. For fgets () functions, line breaks and gets () functions are read on both platforms. line breaks are not read on both platforms.

Reference link:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.