【发布时间】:2013-05-01 16:44:58
【问题描述】:
我的文本文件是这样的
Alex Garcia 1000 userid password
Sana Lopez 300 uid pwd
我正在尝试将上述文本文件保存在二维数组中
ifstream Records("customerdata.txt");
string dataarray[6][6];
if (Records.is_open())
{
while ( Records.good() )
{
for(int i=0; i<6; i++)
{
for(int j=0; j<6; j++)
{
getline(Records,dataarray[i][j],' ');
}
}
}
Records.close();
}
else cout << "Unable to open file";
当我尝试使用 for 循环输出数组时,我会丢失一些值。我不知道我做错了什么。
【问题讨论】:
-
我强烈建议在 StackOverflow 中搜索“[C++] 文本文件数组”。最近这类问题太多了。
-
同时搜索“[c++] parse input file”。
标签: c++ arrays for-loop text-files