2007/07/03 | C++中最简单的对文件的写入操作
类别(计算机与编程) | 评论(0) | 阅读(104) | 发表于 10:04

#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;
}

0

评论Comments

日志分类
首页[666]
计算机与编程[133]
EMU[40]
UFOs[24]
房产[127]
音乐[13]
LOG[0]
经济[120]
影视[3]
物理[7]
数学[8]
社会[105]
职场[9]
生物医学[18]
生活[59]