📄 addressbook.cpp
字号:
// AddressBook.cpp: implementation of the CAddressBook class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AddressBook.h"
#include <iostream>
#include <fstream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAddressBook::CAddressBook()
{
}
CAddressBook::~CAddressBook()
{
}
void CAddressBook::inputInformation()
{
information info;
cout << "请按照提示输入数据!" << endl;
cout << "姓名:" ; cin >> info.name;
cout << "性别:" ; cin >> info.sex;
cout << "年龄:" ; cin >> info.age;
cout << "生日:" ; cin >> info.birthday;
cout << "地址:" ; cin >> info.address;
cout << "电子邮件:" ; cin >> info.email;
cout << "电话:" ; cin >> info.telephone;
cout << "手机:" ; cin >> info.mobile;
cout << "备注:" ; cin >> info.memo;
printInformationToFile(info,"myAdrBook.txt");
}
void CAddressBook::displayFile(char* fileName)
{
ifstream infile(fileName);
if(!infile){
cout << "不能打开文件!\n";
return;
}
char contents[2048] = " ";
while(!infile.eof())
{
infile.getline(contents,sizeof(contents));
cout << contents << endl;
}
}
void CAddressBook::printInformationToFile(information info, char* fileName)
{
ofstream outfile(fileName,ios::app);
outfile << "姓名:" << info.name << endl;
outfile << "性别:" << info.sex << endl;
outfile << "年龄:" << info.age << endl;
outfile << "生日:" << info.birthday << endl;
outfile << "地址:" << info.address << endl;
outfile << "电子邮件:" << info.email << endl;
outfile << "电话:" << info.telephone << endl;
outfile << "手机:" << info.mobile << endl;
outfile << "备注:" << info.memo << endl;
outfile << "-------------------------------" << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -