C++中最简单的对文件的写入操作

      计算机与编程 2007-7-3 10:04:00

#include <iostream>
#include <fstream> //if you want to read or write files...include this...

#include <string>

using namespace std;

main()
{
 ofstream outfile("wangs_data.ini"); //it will be clean...read...mode...
// ofstream outfile("wangs_data.txt",ios_base::app); //it will be append mode read...

 for (int n=1;n<100;n++)
 {
  if (n%2==0)
  {
   if (!outfile)
    cerr << "Oops! unable to save data!\n"; //print to screen...directly...
   else
    cout << "successfully done!\n";
       outfile << "%0 E82AC74 value inserted..." << " " << endl;
  }
  else
  {
   if (!outfile)
    cerr << "Oops! unable to save data!\n";
   else
    cout << "successfully done!\n";
       outfile << "%1 it's a kind of kids..." << " " << endl;
  }

 }; 

 if (!outfile)
  cerr << "Oops! unable to save data!\n";
 else
  cout << "successfully done!\n";
     outfile << "E82AC74" << " " << endl;

 return 0;
}

标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}