228k views
0 votes
Given string inputString on one line and character addChar on a second line, append addChar to inputString.

Ex: If the input is:
Fuzzy bear !
then the output is:
Fuzzy bear!
#include
#include
using namespace std;
int main() {
string inputString;
char addChar;
getline(cin, inputString);
cin >> addChar;
/* Your code goes here */
cout << inputString << endl;
return 0;}

1 Answer

0 votes

Final answer:

To append a character to a string in C++, add the line 'inputString += addChar;' to concatenate the input character to the input string before the output statement.

Step-by-step explanation:

The question pertains to Programming, specifically in appending a character to a string using C++. This task involves reading user input from the console to append a character to a given string using standard input-output streams provided by the C++ library functions.

To answer the question, the code snippet provided will be modified to include an additional line of code within the main function:

inputString += addChar;

This line of code will concatenate the character addChar to the end of the inputString. The program then outputs the modified string to the console.

User Shadi Abo Ahmad
by
7.1k points