+ -
当前位置:首页 → 问答吧 → C++读取文本中的40*50字符到一个二维字符数组中,

C++读取文本中的40*50字符到一个二维字符数组中,

时间:2011-12-17

来源:互联网

Barrack::Barrack(int xx,int yy)
{
fstream ifile;
ifile.open ("D:\\a.txt",ios::in);
string temp;
m_x=xx;
m_y=yy;
char *(tent[4]);
for(int i=0;i<4;i++)
tent[i]=new char[8];
int line=1;
while(getline(ifile,temp))
{
tent[line++]=temp.c_str();///////////////11
}
ifile.close();
}

注释处运行有问题,求大仙帮我改正,最终能够实现将文本中的字符存到这个tent的二维字符数组中去,记得要用C++写啊

作者: lantingyaoyi   发布时间: 2011-12-17

//这样改
int line=0;
while(getline(ifile,temp) && line < 4)
{
strncpy(tent[line],temp,7);
line++;
}

作者: t_y_k_   发布时间: 2011-12-17