how would i remove all the white space from an istream and replace them with "-" before producing an ostream?

maybe

string rem ( string t )
{
   int s_t = t.length();

   for ( int i = 0; i < s_t; i++ )
   {
      if ( t[i] == ' ' || t[i] == '\n' || t[i] == '\t' )
      {
         t[i] = '-';
      }
   }
   return t;
}

or maybe even:

int main(){
    ifstream in("in.txt");
    ofstream out("out.txt");
    string str = "";
    while (in >> str) out << str << "-";
 }

No errorchecking, but it's to get the basic idea

>>while (in >> str) out << str << "-";

What??? That will not replace white spaces with '-' character.

while( in >> str)
{
    for(int i = 0; i < str.length(); i++)
    {
        if( isspace(str[i]) )
          str[i] = '_';
    }
    out << str << "\n";
}


What??? That will not replace white spaces with '-' character.

Why not? Am I missing the point completely or what?

input:

hello 			test test hello
1 2 3

output:

hello-test-test-hello-1-2-3-

Voila, all whitespace has been replaced with "-". That's what the OP wanted right?

And what is your code supposed to do? isspace will never be true because of the way your read in your string ( in >> str )
Perhaps you meant:

while(getline(in,str))
{
    for(int i = 0; i < str.length(); i++)
    {
        if( isspace(str[i]) )
          str[i] = '-';
    }
    out << str << "\n";
}

?

Then the output would be:

hello----test-test-hello
1-2-3

Which could also be what the OP wants :)

Comments
My bad -- you are right :)

Sorry, I misunderstood your code.

>>And what is your code supposed to do?
Nothing -- as you well stated. My post was just a brain fart.

This article has been dead for over six months. Start a new discussion instead.