Creating new files

Creating new files

Post by Carbon » Wed, 19 Jul 2000 04:00:00



I am a totall newbie programmer in C++, and how do i save user info in
seperate text files, like if i wanted to make a program which saves
information to an seperate text file
 
 
 

Creating new files

Post by Donovan Rebbec » Wed, 19 Jul 2000 04:00:00



>I am a totall newbie programmer in C++, and how do i save user info in
>seperate text files, like if i wanted to make a program which saves
>information to an seperate text file

ofstream fout ( "file" );
fout << "Hello world\n";
fout.close();

--
Donovan

 
 
 

Creating new files

Post by Jon Be » Wed, 19 Jul 2000 04:00:00




>I am a totall newbie programmer in C++, and how do i save user info in
>seperate text files, like if i wanted to make a program which saves
>information to an seperate text file

Most any decent C++ book has a whole chapter on using streams, including
"file streams".  But here's a quick example:

#include <iostream>
#include <fstream>

using namespace std;  // quick and dirty namespace hack

int main ()
{
    ofstream MyFile;  // ofstream = "output file stream"
    MyFile.open ("myfile.dat");
    MyFile << "Hello, world!" << endl; // write to MyFile just like to cout
    MyFile.close ();
    return 0;

Quote:}

--

Dept. of Physics and Computer Science        Clinton, South Carolina USA
[ Questions about newsgroups?  Visit http://www.geocities.com/nnqweb/  ]