I am trying to remove blank spaces and replace them to '_' . This program works when you have a defined string, but I am using a string the user propulates from edit txt box or console cin input. It will not display the whole filename. I suspect I am mixing C and C++.

Please help.

Here is the code:

#include <iostream>
#include <string>
using namespace std;

int main()
{

//char out_file_name[19];
string out_file_name;

cout << " Enter output file name with no extention followed by a return \n ";
cout << '\n';
cout << " (For example training ";
cin >> out_file_name;

// string s = "All this will be replaced by this";
string s = out_file_name;
string toFind = " ";
string replaceWith = "_";

// before find and replace
cout << s << endl;

// find and replace operation
int pos;
while ((pos = s.find(toFind)) != string::npos)
s.replace(pos,toFind.size(),replaceWith);

// after find and replace
cout << s << endl;

return 0;
}