stock.cpp

来自「课程设计做的个人股票管理系统」· C++ 代码 · 共 42 行

CPP
42
字号
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include "Stock.h"
#include "GuestStock.h"
#include "Guest.h"



Stock::Stock(long stkCode1, char stkName1[], long stkIss1,
			 double stkOriPrice1, double stkPrice1)
{
	stkCode = stkCode1;
	strcpy(stkName, stkName1);
	stkIss = stkIss1;
	stkOriPrice = stkOriPrice1;
	stkPrice = stkPrice1;
	stkRange = 0;
	stkRank = 0;
}

//从文件中提取数据给对象赋值,尝试()的重载。  -->成功
Stock Stock::operator ()(char fileName[])
{
	ifstream fin(fileName);
	if (!fin)
	{
		cout<<"cannot open"<<endl;
		//exit(0);
	}
	//fin.open((const char *)this, sizeof(Stock));
	fin.seekg(-sizeof(Stock), ios::end);				//“-”似有隐患
	fin.read((unsigned char *)this, sizeof(Stock));
	fin.close();
	return *this;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?