1、文件操作
一、從文件中讀取數(shù)據(jù)ifstream>>
二、往文件中寫入數(shù)據(jù)ofstream<<
//功能:把變量的值寫入到文件中 //將數(shù)組m_name、m_passwd、sex中的數(shù)據(jù)寫入文件中 #include<fstream> #include <string> #include <iostream> using namespace std; int main() {int i=0;int count = 5; //文件中string m_name[5] = {"AA","BB","CC","DD","EE"};string m_passwd[5] = {"1","2","3","4","5"};string sex[5] = {"M","M","W","W","M"};ofstream file_write;file_write.open("name.txt");if(!file_write){cout<<"打開文件失敗"<<endl;}for(i=0;i<count;i++) //注意:空格、endl都可以寫入文件中去file_write<<m_name[i]<<" "<<m_passwd[i]<<" "<<sex[i]<<endl; } 《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結
- 上一篇: 定时器:SetTimer
- 下一篇: 1、用Anaconda配置Windows