C++编写的读取一幅位图的类,在输入位图路径时有有关问题,如果在main函数里直接初始化路径可以实现

C++编写的读取一幅位图的类,在输入位图路径时有问题,如果在main函数里直接初始化路径可以实现
#include <stdio.h>
#include <windows.h>
#include<iostream>
#include<string.h>
#include<istream>
using namespace std;
class bitmapreadandwrite{
public:
unsigned char* pBmpBuf;  //读入图像数据的指针
int bmpWidth;   //图像的宽度
int bmpHeight;   //图像的高度
RGBQUAD* pColorTable;   //颜色表指针
int biBitCount;   //图像类型,像素位数
public:
bitmapreadandwrite(){};
~bitmapreadandwrite()
{
delete[]pBmpBuf;
if (biBitCount == 8)
{
delete[]pColorTable;
}
}
char* getPath();
void show();
bool readBmp(char* bmpName);
bool saveBmp(char* bmpName, unsigned char* imgBuf, int width, int height,
int biBitCount, RGBQUAD* pColorTable);
};
char* bitmapreadandwrite::getPath()
{
cout << "please input the file's path!" << endl;
char path[100];
cin >>path[100];
return path;
}

void bitmapreadandwrite::show()
{
cout << "width=" << bmpWidth << '\t' << "height=" << bmpHeight << '\t' <<
"biBitCount=" << biBitCount << endl;
}
bool bitmapreadandwrite::readBmp(char* bmpName)//定义读取位图进内存的函数,返回值为布尔型,1为读取成功
{
FILE* fp = fopen(bmpName, "rb");          //以二进制读的方式打开指定的图像文件,fp指向打开的二进制文件
if (fp == NULL) return 0;//文件打开失败,返回0

//跳过位图文件头
fseek(fp, sizeof(BITMAPFILEHEADER), 0);//fseek 用于二进制方式打开的文件,移动文件读写指针位置
//SEEK_SET: 文件开头 
//SEEK_CUR: 当前位置
//SEEK_END: 文件结尾
//其中SEEK_SET, SEEK_CUR和SEEK_END和依次为0,1和2
//从文件开头将fp指针移动到位图信息头
//定义位图信息头结构变量,读取位图信息头进内存,存放在变量infoHead中
BITMAPINFOHEADER infoHead; //读取打开的二进制文件的位图信息头进内存,需要定义一个位图信息头变量

fread(&infoHead, sizeof(BITMAPINFOHEADER), 1, fp);//fread函数用于从文件读取一个数据块到存放地址
//savedata(infoHead.biWidth, infoHead.biHeight, infoHead.biBitCount);
bmpWidth = infoHead.biWidth;
bmpHeight = infoHead.biHeight;
biBitCount = infoHead.biBitCount;
//定义变量,计算图像每行像素所占的字节数(必须为4的倍数)
int lineByte = (bmpWidth * biBitCount / 8 + 3) / 4 * 4;

//灰度图像有颜色表,且颜色表为256
if (biBitCount == 8)
{
//申请颜色表所需要的空间,读颜色表进内存
pColorTable = new RGBQUAD[256];//申请动态空间用于存放从位图中读到的颜色表
fread(pColorTable, sizeof(RGBQUAD), 256, fp);
}

//申请位图数据所需要的空间,读位图数据进内存
pBmpBuf = new unsigned char[lineByte * bmpHeight];
fread(pBmpBuf, lineByte * bmpHeight, 1, fp);
fclose(fp);//关闭文件,使用fread和fwrite之后要fclose(fp)
return 1;
}
bool bitmapreadandwrite::saveBmp(char* bmpName, unsigned char* imgBuf, int width, int height,
int biBitCount, RGBQUAD* pColorTable)//bmpName:文件名(路径) imgBuf:图像数据块指针
{
//如果位图数据指针为0,则没有数据输入
if (!imgBuf)
return 0;

//颜色表大小,以字节为单位:灰度图像为1024;彩色图像为0
int colorTablesize = 0;
if (biBitCount == 8)
colorTablesize = 1024;

//待存储图像数据每行字节数为4的倍数
int lineByte = (width * biBitCount / 8 + 3) / 4 * 4;

//以二进制写的方式打开文件
FILE* fp = fopen(bmpName, "wb");
if (fp == NULL) return 0;

//申请位图文件头结构变量,填写文件头信息
BITMAPFILEHEADER fileHead;
fileHead.bfType = 0x4D42;   // bmp 类型

//bfSize是图像文件4个部分之和
fileHead.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)
+colorTablesize + lineByte * height;

fileHead.bfReserved1 = 0;
fileHead.bfReserved2 = 0;

//bfOffBits是图像文件前3个部分所需空间之和
fileHead.bfOffBits = 54 + colorTablesize;

//写文件头进文件
fwrite(&fileHead, sizeof(BITMAPFILEHEADER), 1, fp);

//申请位图信息头结构变量,填写信息头信息
BITMAPINFOHEADER infoHead;

infoHead.biBitCount = biBitCount;
infoHead.biClrImportant = 0;
infoHead.biClrUsed = 0;
infoHead.biCompression = 0;
infoHead.biHeight = height;
infoHead.biPlanes = 1;
infoHead.biSize = 40;
infoHead.biSizeImage = lineByte * height;
infoHead.biWidth = width;
infoHead.biXPelsPerMeter = 0;
infoHead.biYPelsPerMeter = 0;

//写位图信息头进内存
fwrite(&infoHead, sizeof(BITMAPINFOHEADER), 1, fp);

//如果灰度图像,有颜色表,写入文件
if (biBitCount == 8)
fwrite(pColorTable, sizeof(RGBQUAD), 256, fp);

//写位图数据进文件
fwrite(imgBuf, height * lineByte, 1, fp);
fclose(fp);
return 1;
}
int main()
{
bitmapreadandwrite BMP;
BMP.readBmp(BMP.getPath());
BMP.saveBmp(BMP.getPath(), BMP.pBmpBuf, BMP.bmpWidth, BMP.bmpHeight, BMP.biBitCount, BMP.pColorTable);