C/C++ C++: Replacing Characters in A String

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    String
AI Thread Summary
To replace spaces in a 2-character string in C++, check each character of the string for a space. If the 0th character is a space, assign '_' to it; repeat this for the 1st character. The sample program initializes a string called passCode and outputs the modified string. Users are encouraged to implement the character checks and replacements in the provided code section. This approach effectively transforms spaces into underscores in the specified string.
ineedhelpnow
Messages
649
Reaction score
0
Replace any space ' ' by '_' in 2-character string passCode.

Sample program:

Code:
#include 
#include 
#include 
using namespace std;

int main() {
   string passCode;

   passCode = "1 ";
   
<student code>

   

   cout << passCode << endl;
   return 0;
}

I'm super lost on this. I could definitely use some help/hints. Thanks.
 
Technology news on Phys.org
Check if the 0th character is a space. If so, assign [m]'_'[/m] to it. Do the same with the 1st character.
 
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.

Similar threads

Replies
3
Views
5K
Replies
2
Views
7K
Replies
1
Views
2K
Replies
22
Views
3K
Replies
8
Views
2K
Replies
40
Views
3K
Back
Top