Question: Consider the following code fragment: string str1; str2; getline(cin,str1); a. Write a single-statement for loop that will output each character of str1 on a separate
Consider the following code fragment:
string str1; str2; getline(cin,str1);
a. Write a single-statement for loop that will output each character of str1 on a separate line as follows (e.g.) :
H
e
l
l
o
b. Write a for loop to construct a string, str2 that is exactly the same as str1 but without the last character. Use indexing and the length method only. Do not use any other functions.
c. Now write a single C++ statement that will accomplish the same thing as the previous problem using only the length and substr methods (i.e., do not use indexing or loops).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
