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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

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