Deck 21: Class String and String Stream Processing

Full screen (f)
exit full mode
Question
Which function changes the actual string stored in the string object (i.e., is not a const member function)?

A) length
B) empty
C) capacity
D) resize
Use Space or
up arrow
down arrow
to flip the card.
Question
What type of value is returned by the overloaded equality and relational operators for strings?

A) int
B) bool
C) double
D) null
Question
Iterators do not:

A) Allow the characters to be modified.
B) Allow backward traversal of strings.
C) Have range checking.
D) Have syntax similar to pointer operations.
Question
Which of the following is an invalid definition?

A) string sa = "computers";
B) string sb{"computers"};
C) string sc{'c'};
D) string sd{9, 'c'};
Question
Which of the following searches through a string object from right-to-left?

A) find
B) find_first_of
C) find_last_of
D) find_first_not_of
Question
Which of the following is not an argument of the assign member function?

A) The start location.
B) The number of characters to copy.
C) The end location.
D) The string to copy.
Question
Which of the following is not overloaded for strings?

A) -=
B) >>
C) +=
D) getline()
Question
The arguments passed to replace do not include:

A) The subscript of the element where the replace operation ends.
B) The subscript of the element where the replace operation begins.
C) A replacement character string from which a substring is used to replace characters.
D) The element in the replacement character string where the replacement substring begins.
Question
Given the strings defined below, which statement will not return 0? string s1{"Mighty Mouse"};
String s2{"Mickey Mouse"};

A) s1.compare(0, 3, s2, 0, 3);
B) s1.compare(7, 5, s2, 7, 5);
C) s1.compare(8, 12, s2, 8, 12);
D) s1.compare(7, 11, s2, 7, 11);
Question
The function call string1.erase(5) will:

A) Return a copy of string1 minus the character that occupied position 5.
B) Erase all characters up to and including the character in position 5 from string1.
C) Erase all characters starting from and including the character in position 5 to the end of string1.
D) Return a copy of string1 minus every fifth character.
Question
Strings:

A) Can use the subscript operator to access individual characters.
B) Must be null-terminated.
C) Are pointers.
D) Have a first subscript of 1.
Question
If string s1 has the value "computer" and string s2 has the value "promise", which call to insert will produce the string "compromise"?

A) s1.insert(4, s2, 0, string::npos);
B) s1.insert(string::npos, s2, 0, 4);
C) s2.insert(0, s1, 0, 3);
D) s2.insert(3, s1, 0, 3);
Question
If string s1 is lexicographically greater than string s2, then the value returned by s2.compare(0, s2.size(), s1) must be?

A) 0
B) -1
C) A negative number.
D) A positive number.
Question
Which of the following is false?

A) If a string is converted to a C-style array using data, modifying the string could cause the pointer previously returned by data to become invalid.
B) Converting a string containing one or more null characters to a C-style string can cause logic errors.
C) c_str returns a character array of the same length as the string object it is called on.
D) copy implicitly converts a string to a non-null terminated character array.
Question
Which of the following returns a bool?

A) length
B) empty
C) capacity
D) resize
Question
If string s contains "antidisestablishmentarianism", then s.substr(7, 13) would be:

A) "establish"
B) "ishmenta"
C) "establi"
D) "establishment"
Question
Class string has member function __________ to interchange the data stored in two string objects

A) exchange
B) switch
C) swap
D) copyto
Question
The total number of elements that can be stored in a string without increasing its current amount of allocated memory is called its:

A) Size.
B) Length.
C) Capacity.
D) Maximum size.
Question
Which of the following cannot be used to concatenate strings?

A) +
B) +=
C) append
D) assign
Question
Which of the following would not return string::npos when used on the string s which contains "rack":

A) s.find_first_not_of("crackling");
B) s.find_first_not_of("packrat");
C) s.rfind("car");
D) s.find("ack");
Question
Which of the following provides bounds checking?

A) at
B) iterator
C) reverse_iterator
D) [ ]
Question
Which of the following does not apply to an istringstream object?

A) Data is stored in the object as characters.
B) Input from the object works identically to input from any file stream.
C) Data in a string can be appended to it.
D) It is used to inputs data from a string in memory to program variables.
Question
Which of the statements a), b) and c) is false?

A) C++11's header now contains functions for converting from numeric values to string objects and from string objects to numeric values.
B) The to_string function returns the string representation of its numeric argument and is overloaded for types int, unsigned int, long, unsigned long, long long, unsigned long long, float, double and long double.
C) Each C++11 function that converts a string to an integral type receives two parameters-a string containing the characters to convert and a pointer to a size_t variable where the function stores the index of the first character that was not converted (a null pointer, by default).
D) All of the above statements are true.
Question
Which of the following statements about C++11's functions for converting string objects to numeric values is false?

A) Each function attempts to convert its entire string argument to a numeric value.
B) If no conversion can be performed, an invalid_argument exception occurs.
C) If the result of the conversion is out of range for the function's return type, an out_of_range exception occurs.
D) None of the above.
Question
String iterators:

A) Must be dereferenced in order to access the character at each location.
B) Are not range checked.
C) Come in const and non-const forms.
D) All of the above.
Question
What is the code for a loop that iterates from the end of a string toward the beginning?

A) string::reverse_iterator i{s.begin()}; while (i != s.end())
{
Cout << *i;
++i;
}
B) string::reverse_iterator i{s.rbegin()}; while (i != s.rend())
{
Cout << *i;
++i;
}
C) string::reverse_iterator i{s.end()}; while (i != s.begin())
{
Cout << *i;
--i;
}
D) string::reverse_iterator i{s.rbegin()}; while (i != s.rend())
{
Cout << *i;
--i;
}
Question
All of the following are true of an ostringstream object except that:

A) It uses a string to store output data.
B) A stream insertion operation cannot be used to append additional data to it.
C) The string data it stores is dynamically allocated.
D) The data it stores can be accessed using the function str.
Question
The capabilities of inputting and outputting strings in memory are known as:

A) String i/o manipulation.
B) String stream processing.
C) Character handling.
D) Dynamic string operations.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/28
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 21: Class String and String Stream Processing
1
Which function changes the actual string stored in the string object (i.e., is not a const member function)?

A) length
B) empty
C) capacity
D) resize
D
2
What type of value is returned by the overloaded equality and relational operators for strings?

A) int
B) bool
C) double
D) null
B
3
Iterators do not:

A) Allow the characters to be modified.
B) Allow backward traversal of strings.
C) Have range checking.
D) Have syntax similar to pointer operations.
C
4
Which of the following is an invalid definition?

A) string sa = "computers";
B) string sb{"computers"};
C) string sc{'c'};
D) string sd{9, 'c'};
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following searches through a string object from right-to-left?

A) find
B) find_first_of
C) find_last_of
D) find_first_not_of
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following is not an argument of the assign member function?

A) The start location.
B) The number of characters to copy.
C) The end location.
D) The string to copy.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following is not overloaded for strings?

A) -=
B) >>
C) +=
D) getline()
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
8
The arguments passed to replace do not include:

A) The subscript of the element where the replace operation ends.
B) The subscript of the element where the replace operation begins.
C) A replacement character string from which a substring is used to replace characters.
D) The element in the replacement character string where the replacement substring begins.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
9
Given the strings defined below, which statement will not return 0? string s1{"Mighty Mouse"};
String s2{"Mickey Mouse"};

A) s1.compare(0, 3, s2, 0, 3);
B) s1.compare(7, 5, s2, 7, 5);
C) s1.compare(8, 12, s2, 8, 12);
D) s1.compare(7, 11, s2, 7, 11);
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
10
The function call string1.erase(5) will:

A) Return a copy of string1 minus the character that occupied position 5.
B) Erase all characters up to and including the character in position 5 from string1.
C) Erase all characters starting from and including the character in position 5 to the end of string1.
D) Return a copy of string1 minus every fifth character.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
11
Strings:

A) Can use the subscript operator to access individual characters.
B) Must be null-terminated.
C) Are pointers.
D) Have a first subscript of 1.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
12
If string s1 has the value "computer" and string s2 has the value "promise", which call to insert will produce the string "compromise"?

A) s1.insert(4, s2, 0, string::npos);
B) s1.insert(string::npos, s2, 0, 4);
C) s2.insert(0, s1, 0, 3);
D) s2.insert(3, s1, 0, 3);
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
13
If string s1 is lexicographically greater than string s2, then the value returned by s2.compare(0, s2.size(), s1) must be?

A) 0
B) -1
C) A negative number.
D) A positive number.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following is false?

A) If a string is converted to a C-style array using data, modifying the string could cause the pointer previously returned by data to become invalid.
B) Converting a string containing one or more null characters to a C-style string can cause logic errors.
C) c_str returns a character array of the same length as the string object it is called on.
D) copy implicitly converts a string to a non-null terminated character array.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following returns a bool?

A) length
B) empty
C) capacity
D) resize
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
16
If string s contains "antidisestablishmentarianism", then s.substr(7, 13) would be:

A) "establish"
B) "ishmenta"
C) "establi"
D) "establishment"
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
17
Class string has member function __________ to interchange the data stored in two string objects

A) exchange
B) switch
C) swap
D) copyto
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
18
The total number of elements that can be stored in a string without increasing its current amount of allocated memory is called its:

A) Size.
B) Length.
C) Capacity.
D) Maximum size.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following cannot be used to concatenate strings?

A) +
B) +=
C) append
D) assign
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following would not return string::npos when used on the string s which contains "rack":

A) s.find_first_not_of("crackling");
B) s.find_first_not_of("packrat");
C) s.rfind("car");
D) s.find("ack");
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following provides bounds checking?

A) at
B) iterator
C) reverse_iterator
D) [ ]
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following does not apply to an istringstream object?

A) Data is stored in the object as characters.
B) Input from the object works identically to input from any file stream.
C) Data in a string can be appended to it.
D) It is used to inputs data from a string in memory to program variables.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the statements a), b) and c) is false?

A) C++11's header now contains functions for converting from numeric values to string objects and from string objects to numeric values.
B) The to_string function returns the string representation of its numeric argument and is overloaded for types int, unsigned int, long, unsigned long, long long, unsigned long long, float, double and long double.
C) Each C++11 function that converts a string to an integral type receives two parameters-a string containing the characters to convert and a pointer to a size_t variable where the function stores the index of the first character that was not converted (a null pointer, by default).
D) All of the above statements are true.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following statements about C++11's functions for converting string objects to numeric values is false?

A) Each function attempts to convert its entire string argument to a numeric value.
B) If no conversion can be performed, an invalid_argument exception occurs.
C) If the result of the conversion is out of range for the function's return type, an out_of_range exception occurs.
D) None of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
25
String iterators:

A) Must be dereferenced in order to access the character at each location.
B) Are not range checked.
C) Come in const and non-const forms.
D) All of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
26
What is the code for a loop that iterates from the end of a string toward the beginning?

A) string::reverse_iterator i{s.begin()}; while (i != s.end())
{
Cout << *i;
++i;
}
B) string::reverse_iterator i{s.rbegin()}; while (i != s.rend())
{
Cout << *i;
++i;
}
C) string::reverse_iterator i{s.end()}; while (i != s.begin())
{
Cout << *i;
--i;
}
D) string::reverse_iterator i{s.rbegin()}; while (i != s.rend())
{
Cout << *i;
--i;
}
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
27
All of the following are true of an ostringstream object except that:

A) It uses a string to store output data.
B) A stream insertion operation cannot be used to append additional data to it.
C) The string data it stores is dynamically allocated.
D) The data it stores can be accessed using the function str.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
28
The capabilities of inputting and outputting strings in memory are known as:

A) String i/o manipulation.
B) String stream processing.
C) Character handling.
D) Dynamic string operations.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 28 flashcards in this deck.