C++: Replacing Characters in A String

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    String
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 5K views
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.
 
Physics 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.