Which of the following are correct uses of std::string constructors?
A. string s1;
B. string s2(s1);
C. string s3{7};
D. string s4{'a'};
E. string s5{7, 'a'};
Choose the most appropriate answer from the options given below:
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. A, B, D, E only
Explanation
Default construction, copy construction and brace-initialisation with characters ({'a'}, and {7, 'a'} as an initializer list of chars) are standard uses. s3{7} creates a one-character string with code 7, which is not the intended 'length 7', so it is excluded in the keyed answer.More Programming Languages and Computer Graphics questions
- A corporate website's appearance varies according to the department that owns the documents, but all documents follow the corporate look an…
- Match List I with List IIList I List II A. 2-D Array Input I. Liquid Crystal Display B. Transmissive device II. Flat-bed scanner C. Binary…
- Consider the following conditional code, which returns a Boolean value:if ((x > 25) && (y > 100)) return 'false'; else if ((x <= 25) && (y…
- Machine level language is a/an
- Which of the following is wrong about data types?
- If a constructor 'Date' is declared explicit and has to be defined outside the class, which of the following is correct?