writing to file

I am very new and just need code to prompt the user for information and to write that information to a file such as file.doc.
Hi,

I'm new to, but this seems like a good place to start:

http://www.cplusplus.com/doc/tutorial/files.html
For a simple text file:


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream.h>
#include <string>
#include <fstream>
using namespace std;

int main() {
  string stringVar;                       // here's your input variable
  getline(cin, stringVar, '\n');          // here's how to get some input
  ofstream ofile("C:\\FILE.DOC");         // this opens your file
  if (ofile) ofile << stringVar << endl;  // this writes your input variable to file
  ofile.close();                          // this closes your file
}


That's just a basic example of how you can write to a file.
Topic archived. No new replies allowed.