Using substr and concatenation, give a program containing a sequence of commands that will extract characters from input_string = "Four score and seven years ago our fathers" to make output_string = "carefree and no tears". Then print output_string.
Here is my code:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
to extract "carefree and no tears" in my output stream using substr and concatenation, what would I do? What i was attempting to do (although it doesn't make sense in my code) is extract the column, and the number of letters in "Four score and seven years ago our fathers" to create "carefree and no tears".
You need to build upon what you have, using the concatenation operator'+'.
Simple example of concatenation:
1 2 3 4 5 6 7 8 9
string one = "mess";
string two = "age";
string three = " in a ";
string four = "bottle";
one = one + two;
one += three + four;
cout << one << endl;
Output:
message in a bottle
Lines 6 and 7 above do more or less the similar things, but the += operator is more concise.
You need to use this concatenation operator multiple times with individual substrings such as input_string.substr(11, 1) or input_string.substr(22, 4) as required.
Actually, if you only need a single character, you could use input_string[11], but that may not be allowed in your project.