title: how can I replace all the whitespace chars with another character using input & output stream manipulators?
body: <p>For example, I get an input from the user using <code>std::cin</code>:</p>
  
  <p><code>"This is a sample program"</code></p>
  
  <p>I want to replace every whitespace with another char and display it back like:</p>
  
  <p><code>"This\is\a\sample\program"</code></p>
  
  <p>Note: other characters can be anything. ex: <code>*</code> or <code>&amp;</code> or <code>$</code>, etc.</p>
  
  <p>I want to do this using stream manipulator. Is it possible?</p>
  
  <p>Here is some sample code which I tried using std::getline but this is not the kind of code I'm expecting. I want to do this using any existing <code>i/o stream Manipulators</code> or my own manipulator.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  string spaceToStar(string text){
      for (int i=0;i&lt;sizeof(text);i++){
          if(text[i] == ' ')
              text[i] = '*';
      }
      return text;
  }
  
  int main () {
      string text, s;
      cout &lt;&lt; "enter your line: " &lt;&lt; endl;
      getline(cin, text);
  
      s = spaceToStar(text);
  
      cout &lt;&lt; s &lt;&lt; endl;
  
  
    return 0;
  }
  </code></pre>