MHB The code should be:cout << secretID + spaceChar + lastName << endl;

  • Thread starter Thread starter ineedhelp420
  • Start date Start date
AI Thread Summary
The discussion centers on combining two strings in C++ to output "Barry Allen." The original code initializes two strings, `secretID` and `lastName`, and a character for space. To achieve the desired output, the correct approach involves using `push_back` for adding a character and `append` for adding a string. Specifically, `secretID.push_back(spaceChar)` adds a space, followed by `secretID.append(lastName)` to concatenate the last name. This distinction between `push_back`, which expects a character, and `append`, which expects a string, is crucial for correctly combining the strings.
ineedhelp420
Messages
1
Reaction score
0
Code:
#include <iostream>
#include <string>
using namespace std;

int main() {
   string secretID = "Barry";
   string lastName = "Allen";
   char spaceChar = ' ';

 /* Your solution goes here  */

   cout << secretID << endl;
   return 0;
}

I don't understand this. i need help
i'm suppose to out put "Barry Allen" but what do i push back?

Retype and correct the code provided to combine two strings separated by a space. Hint: What type of parameter does push_back expect?

Code:
   secretID.push_back(spaceChar);
   secretID.push_back(lastName);
 
Last edited by a moderator:
Technology news on Phys.org
You can use the following code.

Code:
 secretID.push_back(spaceChar);
 secretID.append(lastName);

The [m]push_back[/m] method adds a character to the end of the line, while [m]append[/m] adds another string.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top