manageFeatures(字符串输入,字符串输出,字符串命令)似乎我的代码有一些导致调试错误的问题。调试错误消息是:project4.exe中0x00EDDFF6处抛出异常:0xC0000005:访问冲突写入位置0xDDDDDDD。我的代码应该读取输入文件,其中19个信息在一行中被分隔。我打算逐行阅读,将信息保存到“features”结构中。数组的初始大小为10.每当达到完整大小时,它应该是数组大小的两倍。
ifstream in;
in.open(input);
ifstream com;
com.open(commands);
ofstream out;
out.open(commands);
int size = 10;
int count = 0;
string line;
features * array = new features[size];
while (getline(in, line))
{
if (count == (size - 1))
{
features * temp = new features[size * 2];
for (int i = 0; i < size; i++)
{
*(temp + i) = *(array + i);
}
array = temp;
size = size * 2;
delete[] temp;
}
stringstream ssm(line);
getline(ssm, array[count].geonameid, '\t');
getline(ssm, array[count].name, '\t');
getline(ssm, array[count].asciiname, '\t');
getline(ssm, array[count].alternatenames, '\t');
getline(ssm, array[count].latitude, '\t');
getline(ssm, array[count].longtitude, '\t');
getline(ssm, array[count].feature_class, '\t');
getline(ssm, array[count].feature_code, '\t');
getline(ssm, array[count].country_code, '\t');
getline(ssm, array[count].cc2, '\t');
getline(ssm, array[count].admin1_code, '\t');
getline(ssm, array[count].admin2_code, '\t');
getline(ssm, array[count].admin3_code, '\t');
getline(ssm, array[count].admin4_code, '\t');
getline(ssm, array[count].population, '\t');
getline(ssm, array[count].elevation, '\t');
getline(ssm, array[count].dem, '\t');
getline(ssm, array[count].timezone, '\t');
getline(ssm, array[count].modification_date, '\t');
count++;
}
out << "File: " << input << " Count: " << count << endl;
string command, id1, id2, name;
com >> command;
while (!com.fail())
{
if (command == "find-id")
{
com >> id1;
find_id(array, id1, out);
}
if (command == "find-name")
{
com >> name;
find_name(array, name, out);
}
if (command == "distance")
{
com >> id1 >> id2;
distance(array, id1, id2, out);
}
if (command == "radius")
{
}
if (command == "more-info")
{
}
com >> command;
}