Answers

Question and Answer:

  Home  Basic C++ Syntax

⟩ What is prototype for that C string function?

The prototype for that function is:

istream& getline(char *buffer, int length, char terminal_char);

The char *buffer is a pointer to the first element of the character array, so that it can actually be used to access the array. The int length is simply how long the string to be input can be at its maximum (how big the array is). The char terminal_char means that the string will terminate if the user inputs whatever that character is. Keep in mind that it will discard whatever the terminal character is.

It is possible to make a function call of cin.getline(arry, 50); without the terminal character. Note that 'n' is the way of actually telling the compiler you mean a new line, i.e. someone hitting the enter key.

For a example:

#include

using namespace std;

int main()

{

char string[256]; // A nice long string

cout<<"Please enter a long string: ";

cin.getline ( string, 256, 'n' ); // Input goes into string

cout<<"Your long string was: "<< string <

cin.get();

}

 181 views

More Questions for you: