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

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    String
Click For 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
12
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
3K
  • · Replies 118 ·
4
Replies
118
Views
9K