av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

C語(yǔ)言

c語(yǔ)言文件創(chuàng)建與建立

時(shí)間:2025-01-13 23:30:38 C語(yǔ)言 我要投稿

c語(yǔ)言文件創(chuàng)建與建立

  C語(yǔ)言是一門(mén)通用計(jì)算機(jī)編程語(yǔ)言,應(yīng)用廣泛。下面是小編分享的c語(yǔ)言文件創(chuàng)建與建立,一起來(lái)看一下吧。

  今天給大家分享的是有關(guān)文件的創(chuàng)建與讀取的語(yǔ)法,事實(shí)上,c語(yǔ)言中對(duì)于這方面的已經(jīng)有相當(dāng)經(jīng)典且應(yīng)用相當(dāng)廣泛的語(yǔ)法了,但是我今天想講一講關(guān)于c++中的相關(guān)語(yǔ)法,以下是代碼:

  首先是文件的創(chuàng)建:

  # include

  # include

  # include

  using namespace std;

  int main() {

  ofstream outclientfile("clients.dat", ios::out);

  if (!outclientfile) {

  cerr << "file could not be opend" << endl;

  exit(1);

  }

  cout << "enter the account,name,and balance." << endl;

  cout<< "enter end-of-file to end input. ?";

  int account;

  char name[30];

  double balance;

  while (cin >> account >> name >> balance) {

  outclientfile << account << " " << name << " " << balance << endl;

  cout << "?";

  }

  system("pause");

  return 0;

  }

  以下是文件的讀取:

  # include

  # include

  # include

  # include

  # include

  using namespace std;

  void outputline(int, const string, double);

  int main() {

  ifstream inclientfile("clients.dat", ios::in);

  if (!inclientfile) {

  cerr << "file could not be opened" << endl;

  exit(1);

  }

  int account;

  char name[30];

  double balance;

  cout << left << setw(10) << "account" << setw(13) << "name"

  << "balance" << endl<<fixed<<showpoint;< p="">

  while (inclientfile >> account >> name >> balance) {

  outputline(account, name, balance);

  }

  system("pause");

  return 0;

  }

  void outputline(int account, const string name, double balance) {

  cout << left << setw(10) << account << setw(13) << name

  << setw(7) << setprecision(2) << right << balance << endl;

  }

  知識(shí)點(diǎn):以文件的創(chuàng)建為例,我們?cè)陬^文件中使用# include包含了ofstream類(lèi),并且在主程序中使用類(lèi)ofstream建立了名為outclientfile對(duì)象,并且初始化其構(gòu)造函數(shù)。要注意的是我們?cè)趙hile只是判斷條件的真假,而類(lèi)outclientfile進(jìn)行輸入數(shù)據(jù)。

【c語(yǔ)言文件創(chuàng)建與建立】相關(guān)文章:

C語(yǔ)言文件的創(chuàng)建與建立08-12

c語(yǔ)言—文件的創(chuàng)建與建立01-12

怎么利用c語(yǔ)言創(chuàng)建excel文件08-13

C語(yǔ)言文件03-02

C語(yǔ)言的文件概念07-18

C語(yǔ)言文件操作的方法03-29

C語(yǔ)言文件操作函數(shù)05-22

C語(yǔ)言頭文件封裝06-25

C語(yǔ)言文件操作教程05-11