x1 is used for the cout.write() to write only the number of characters in the original string. This is done because string is a character array with a size between 1 and 80. the strlen function figures out how big it really is and then only that many elements are written in the cout. There are a lot of C references here. If you want to make it c++, use the std::string type instead of making a character array.
I would just do the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream.h>
usingnamespace std;
int main ()
{
std::string TheString
cout<<"Enter string \n";
cin.getline(TheString);
for(int i=0;i <TheString.size();i++)
if(TheString[i]==' ')
TheString[i]='_';
cout<<"The changed string is \n" << TheString;
return 0;
}