View Single Post
  #1 (permalink)  
Old February 25th, 2007, 07:26 PM
Bourne Bourne is offline
Registered User
 
Join Date: Feb 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Bourne
Default Simple (noob) Question

I am new to C++ (as is evident by this simple quewstion), but if anybody could take the time to help..

I am trying to get a simple program to write user-specified contents to a file. I have the basics working, but it will cut anything off from the content after a space is entered. Here is the code I have. (I realize this is probably not the best way to go about doing this, but I'm trying to keep it simple, as I am still very new to C++ programming.

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string content;
int main () {

    cout << "Enter your content: ";
    cin >> content;

  ofstream myfile;
  myfile.open ("example.txt");
  myfile << content; //this does not allow spaces; only the first set of chars before the space will be included
  myfile.close();
  return 0;
}
When the program is ran, anything after a space in the entered content is cut off, and is not written to the file.

Any help would be appriciated.

Reply With Quote