【 莫挨老子 】 2019-01-05 16:29
浏览 315

关于一段文本的读入,这一段代码是如何实现读入一个文件的,老师上课演示的,并不是很明白

bool CRSImage::ReadMetaData(const char* lpstrMetaFilePath)
{
ifstream ifs; //input file stream
string strLine;
string strSubTxt;
stringstream ss; //string stream
char sBuff[260];
ifs.open(lpstrMetaFilePath, ios_base::in);
if (!ifs.is_open())
return false;
while (!ifs.eof()) //end of file
{
ifs.getline(sBuff, 260);
strLine = sBuff;

ss.clear();
ss.str(strLine); //"samples = 640"
ss >> strSubTxt;
if (strSubTxt == "samples")
{
ss >> strSubTxt >> m_nSamples;
}
else if (strSubTxt == "lines")
{
ss >> strSubTxt >> m_nLines;
}
else if (strSubTxt == "bands")
{
ss >> strSubTxt >> m_nBands;
}
else if (strSubTxt == "interleave")
{
ss >> strSubTxt >> strSubTxt;
if (strSubTxt == "bsq")
{
m_eInterleave = BSQ;
}
else if (strSubTxt == "bip")
{
m_eInterleave = BIP;
}
else if (strSubTxt == "bil")
{
m_eInterleave = BIL;
}
else
{
// blank
}
}
else if (strSubTxt == "data")
{
ss >> strSubTxt;
if (strSubTxt == "type")
{
ss >> strSubTxt >> m_nDataType;
}
}
else
{

        }


    }
    return true;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 chatglm-6b应用到django项目中,模型加载失败
    • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
    • ¥15 CreateBitmapFromWicBitmap内存释放问题。
    • ¥30 win c++ socket
    • ¥30 CanMv K210开发板实现功能
    • ¥15 C# datagridview 栏位进度
    • ¥15 vue3页面el-table页面数据过多
    • ¥100 vue3中融入gRPC-web
    • ¥15 kali环境运行volatility分析android内存文件,缺profile
    • ¥15 写uniapp时遇到的问题