Code:
1: //Listing 11.9 using cin.get()
2:
3: #include <iostream.h>
4:
5: int main()
6: {
7: char buffer[80];
8: cout << "Enter the string: ";
9: cin.get(buffer, 79); // get up to 79 or newline
10: cout << "Here's the buffer: " << buffer << endl;
11: return 0;
12: }
1: //Listing 11.9 using cin.get()
2:
3: #include <iostream.h>
4:
5: int main()
6: {
7: char buffer[80];
8: cout << "Enter the string: ";
9: cin.get(buffer, 79); // get up to 79 or newline
10: cout << "Here's the buffer: " << buffer << endl;
11: return 0;
12: }
Output: Enter the string: Hello World
Here's the buffer: Hello World
Analysis: Line 9 calls the method get() of cin. The buffer declared in line 7 is passed in as the first argument. The second argument is the maximum number of characters to get. In this case, it must be 79 to allow for the terminating null. There is no need to provide a terminating character because the default value of newline is sufficient.
PITANJE:
U opisu KODA, sta znaci recenica koju sam boldao (crvene boje), odnosno sta znaci: podrazumjevana vrednost NEWLINE, pa ne treba karakter za terminaciju?
Ako moze da malo objasnite sta je "pisac htio reci"?
PS: znam da je banalno pitanje ali ipak bi htio sta se mislilo tacno pod ovom izjavom!