求助!字符串读取错误!

#include"stdafx.h"
#include<stdio.h>
#include
#include
#include
using namespace std;
#define INFINITY INT_MAX //定义无穷大
typedef enum { FALSE, TRUE }Boolean;
typedef struct { //图上的点,即城市
bool pass = false;
string country, city;
float L, B;
}City, Vertex;
typedef struct { //图上的边,即路径
string origin_city, destination_city, transport, other_information;
float time, cost;
}Route, Arc;
typedef struct { //图
Vertex *vertex;
Arc arcs[199][199];
int vexnum, arcnum;
}MGragh;

bool readfile(char* CtFile, char* RtFile, City* ct, Route* rt) {
//存城市信息
FILE *fp = nullptr;
errno_t err = fopen_s(&fp, CtFile, “r”);
if (fp == NULL)
return false;
char ch;
float f;
int i = 0;
while (!feof(fp)) {
//按”行“进行读取
//先读取字符信息
ch = fgetc(fp);
for (; ch != ‘,’; ch = fgetc(fp)) {
ct[i].country += ch;
}
ch = fgetc(fp);
for (; ch != ‘,’; ch = fgetc(fp)) {
ct[i].city += ch;
}
//再读取数字信息
fscanf_s(fp, “%f,”, &f);
ct[i].L = f;
fscanf_s(fp, “%f\n”, &f);
ct[i].B = f;
i++;
}
//关闭文件
fclose(fp);
//存路径信息
FILE *fp1 = nullptr;
errno_t err1 = fopen_s(&fp1, RtFile, “r”);
if (fp1 == NULL)
return false;
i = 0;
ch = fgetc(fp1);
while (!feof(fp1)) {
while (ch != ‘,’) {
rt[i].origin_city += ch;
ch = fgetc(fp1);
}
ch = fgetc(fp1);
while (ch != ‘,’) {
rt[i].destination_city += ch;
ch = fgetc(fp1);
}
ch = fgetc(fp1);
while (ch != ‘,’) {
rt[i].transport += ch;
ch = fgetc(fp1);
}
fscanf_s(fp1, “%f,”, &rt[i].time);
fscanf_s(fp1, “%f,”, &rt[i].cost);
ch = fgetc(fp1);
while (ch != ‘\n’) {
rt[i].other_information += ch;
ch = fgetc(fp1);
}
ch = fgetc(fp1);
i++;
}
fclose(fp1);

return true;

}
运行后string值读不上,调试后,其值为
std::_String_alloc<std::_String_base_types<char,std::allocator > > = {_Mypair={_Myval2={_Bx={_Buf=0x413fc910 “Afghanistan” _Ptr=0x68676641 <读取字符串的字符时出错。> _Alias=0x413fc910 “Afghanistan” } …} } }
有大神知道改怎么改吗!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值