Oldman, your code has several errors and problems - did you compile and run it?
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
char filename[24]; /*Better use std::string,
at least 256 characters should be allowed anyway */
ifstream MyFile;
cout<<"enter filename";
cin>> filename;
MyFile.open(filename.c_str(), ios::in);
if (MyFile.good());/*because of the semicolon!
the following block is always executed.
Why don't you do anything if the file couldn't be opened? */
{
cout<<"good open\n";
}
while (!MyFile.eof()) //bad way to control input loop
{
string ws_left, word; //whitespace
/*What do you expect to happen here?
This will just skip some words?*/
getline(MyFile,ws_left,' ');
MyFile>>word;
//why not open the file once outside the loop?
ofstream out("output.txt",ios::out |ios::app);
out<<word<<" ";
}
MyFile.close();
out.close(); //out is out of scope here
cin.get(); //Won't stop because the input buffer has a leftover endline
return 0;
}