Question: I'm trying to make a program that will get the user input of a new file name, create the file, and write to it. It works but it will only write the first word of the string to the file. How can i get it to write the full string? thanks.

```
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
for (;;)
{
     char  *myFile = " "; 
     string f = " ";
     string w = " ";
     cout <<"What is the name of the file you would like to write to? " <<endl;
     cin >>f;
     ofstream myStream(f,ios_base::ate|ios_base::out);

     cout <<"What would you like to write to " <<f <<" ? ";
     cin >>w;

     myStream <<w;

  if (myStream.bad())
  {
     myStream <<"A serious error has occured.";
     myStream.close();
     break;
  }
}

}

```

Answer: 
According to [this post](https://stackoverflow.com/questions/5455802/how-to-read-a-complete-line-from-the-user-using-cin), you should consult [this reference](http://www.cplusplus.com/reference/fstream/fstream/) to use a method like getline().

Also, when you are writing out I recommend that you flush the output (cout.flush()) before ending the program, especially in this case, since I presume you are ending the program with a ctrl-C break.

In formulating a suggestion, I will read data into char\*, and convert them to "string" in case you will use them elsewhere in your program.

I tested this code in MS Visual C++ Express.

```
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    for (;;)
    {
        char  *myFile = new char[200]; // modified this line

        //added this line
        char *myInput = new char[200];

        string f = " ";
        string w = " ";
        cout << "What is the name of the file you would like to write to? " << endl;
        cin.getline(myFile, 200);//modified this line
        f = (myFile);//added this line
        cin.clear(); //added this line
        ofstream myStream(f, ios_base::ate | ios_base::out);

        cout << "What would you like to write to " << f << " ? ";

        cin.getline(myInput, 200);//edited this line

        w = string(myInput);//added this line

        myStream << w;
        myStream.flush();//added this line

        if (myStream.bad())
        {
            myStream << "A serious error has occured.";
            myStream.close();
            break;
        }

        delete myFile;
        delete myInput;
    }

}

```
`cin<<w;` cin would stop consuming input character when it encounter whitespace tab and other unseeable characters.

you should probably use `std::getline()` instead.
take a look at this page for ref.
<http://en.cppreference.com/w/cpp/string/basic_string/getline>

Or you can use manipulator to not skip whitespace.