fstream读写文件

来源:互联网 发布:世界省市区数据库 编辑:程序博客网 时间:2024/04/28 06:06
ifstream infile;
//打开文件
infile.open("input_assign01_01.dat");
if(!infile)
{
cout << "unable to open data file"<<endl;
return -1;
}
char str[255];
while(!infile.eof()) 

infile.getline(str,255); //此时str为char[]类型

//getline(infile,str); //此时str为string类型

int len = strlen(str);
if(len ==1)
n = str[0] - '0';
else
{
x[i] = str[0]-'0';
y[i] = str[2]-'0';
cout << "Resident Location "<< i << ": (" << x[i] << "," << y[i] << ")" <<endl;
i++;
}
}
原创粉丝点击