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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started