一下纯属个人总结、欢迎拍砖!谢谢
我意思到以练促进学习C++编程基础是很有帮助的
这篇文章是我为了熟悉掌握文件流和STL中的vector以及结构体三个只知识点所写的代码:
#include <string>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
struct cashier
{
string cashierNumber;
string password;
};
cashier _cashier;
vector <cashier> account;
void main()
{
ofstream root_file;
root_file.open("d:\rootNumber.txt ",ios::out);
if (!root_file)
{
cout<< "创建根账户失败!"<<endl;
}
_cashier.cashierNumber="888888";
_cashier.password="888888";
account.push_back(_cashier);
for (vector<cashier>::iterator it=account.begin();
it!=account.end();it++)
{
root_file<<it->cashierNumber<<" ";
root_file<<it->password;
}
root_file.close();
system("pause");
}
在磁盘中生成的文件如下图所示:
原文链接: https://www.cnblogs.com/hww836967373/archive/2013/04/30/3051537.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/86578
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!