Review of C++ Input and Output



sizeof ( ) operator

can be used to return the size, in bytes, of the given expression or type

used with the array name, the number of bytes in the whole array is returned.

cin.getline()

cin.get(ch); // will read any character input into ch.

cin.getline(s3, length);// will read any characters input

// into string s3, until input is '\n' or

// length-1 is reached, then appends '\0' to s3.

String

a character array with a null symbol (\0) placed immediately after the last character.

The length of the longest possible string is one less than the size of the array.

int main()

{

char a[10] = {'y','e','s'}; // NOT a string

char s[10] = "yes"; // cstring, s[3] has '\0' from system.

char t[4] = "yes"; // cstring, with just enough space

}

1. A string can be assigned an initial value when declared. But the assignment is not allowed anywhere else in the program

char s1[20]; // uninitialized

char s2[10] = "Class 310"; // spaces are allowed

char s3[] = "hello"; // if the length is not specified,

// compiler automatically determines

// the size needed

char s4[] = ""; // empty string

• Strings can be used for reading and writing

cout > s3; // OK. white space skipped and then

// assign to s3 till next whitespace.

// Null terminator is added at the end.

cout ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download