文件内容:
SD 1 1 178 123 1 195 106 1 0
DD 5 5 267 85 1 299 57 57 0
......
DD 10 10 515 85 3 492 57 60 0
DX 1 D1 150 113 0
LX 11 S1 329 92 1
......
LX 19 X 83 73 0
YC1 1 1DG 150 125 1 227 125 178 123 1 1
YC1 2 2DG 580 125 3 670 125 659 123 2 1
......
WC 11 1G 338 87 0 490 87
......
YC2 60 6-10DG 490 87 9 595 87 515 85 10 1 566 89 8 1
YC2 57 5-7DG 232 87 8 337 87 267 85 5 1 287 89 9 1然后用下面的方法读取:
CString buf, sTemp;
while (file.ReadString(buf)) {
sTemp = buf;
strtemp1 = strtok(sTemp.GetBuffer(0), " ");
if (strtemp1 == "SD" || strtemp1 == "DD" ) {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2, &itemp2, &engross);
pDoc->branch[m++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2, itemp2, engross);
}
if (strtemp1 == "DX" || strtemp1 == "LX") {
sscanf(buf.GetBuffer(0), "%S %d %s %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr);
pDoc->signal[n++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr);
}
if (strtemp1 == "YC1") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2, &x3, &y3, &itemp2, &itemp3);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2, x3, y3, itemp2, itemp3);
}
if (strtemp1 == "WC") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2);
}
if (strtemp1 == "YC2") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d",strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr, &x2, &y2,
&x3, &y3, &itemp2, &itemp3, &x4, &y4, &itemp4, &itemp5);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2, x1, y1,
atrr, x2, y2, x3, y3, itemp2, itemp3, x4, y4, itemp4, itemp5);
}
}
现在前2种情况都能够读了,但是后面3种却不行。
其中YC1情况能够读,但是不正确,后面两种WC和YC2一读就错误。
哪位知道为什么?应该怎么改正?
谢谢!!
SD 1 1 178 123 1 195 106 1 0
DD 5 5 267 85 1 299 57 57 0
......
DD 10 10 515 85 3 492 57 60 0
DX 1 D1 150 113 0
LX 11 S1 329 92 1
......
LX 19 X 83 73 0
YC1 1 1DG 150 125 1 227 125 178 123 1 1
YC1 2 2DG 580 125 3 670 125 659 123 2 1
......
WC 11 1G 338 87 0 490 87
......
YC2 60 6-10DG 490 87 9 595 87 515 85 10 1 566 89 8 1
YC2 57 5-7DG 232 87 8 337 87 267 85 5 1 287 89 9 1然后用下面的方法读取:
CString buf, sTemp;
while (file.ReadString(buf)) {
sTemp = buf;
strtemp1 = strtok(sTemp.GetBuffer(0), " ");
if (strtemp1 == "SD" || strtemp1 == "DD" ) {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2, &itemp2, &engross);
pDoc->branch[m++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2, itemp2, engross);
}
if (strtemp1 == "DX" || strtemp1 == "LX") {
sscanf(buf.GetBuffer(0), "%S %d %s %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr);
pDoc->signal[n++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr);
}
if (strtemp1 == "YC1") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2, &x3, &y3, &itemp2, &itemp3);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2, x3, y3, itemp2, itemp3);
}
if (strtemp1 == "WC") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d",
strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr,
&x2, &y2);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2,
x1, y1, atrr, x2, y2);
}
if (strtemp1 == "YC2") {
sscanf(buf.GetBuffer(0), "%s %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d",strtemp1, &itemp1, strtemp2, &x1, &y1, &atrr, &x2, &y2,
&x3, &y3, &itemp2, &itemp3, &x4, &y4, &itemp4, &itemp5);
pDoc->track[l++].InitData(strtemp1, itemp1, strtemp2, x1, y1,
atrr, x2, y2, x3, y3, itemp2, itemp3, x4, y4, itemp4, itemp5);
}
}
现在前2种情况都能够读了,但是后面3种却不行。
其中YC1情况能够读,但是不正确,后面两种WC和YC2一读就错误。
哪位知道为什么?应该怎么改正?
谢谢!!
file.Open (m_FileName, CFile::modeRead | CFile::shareDenyWrite);
这里应该没问题吧。
我是指前面if (strtemp1 == "SD" || strtemp1 == "DD" )和if (strtemp1 == "DX" || strtemp1 == "LX") 两种情况可以正确读出数据。
而后面的if (strtemp1 == "YC1") ,if (strtemp1 == "WC") ,if (strtemp1 == "YC2")
读入不了数据。
好像加了ReleaseBuffer也不行啊
现在的情况就是一加上后面if (strtemp1 == "WC") ,if (strtemp1 == "YC2") 的内容
运行就会出错。
只有注释掉if (strtemp1 == "WC") ,if (strtemp1 == "YC2") 的代码才可以运行,
其中由if (strtemp1 == "SD" || strtemp1 == "DD" )和if (strtemp1 == "DX" || strtemp1 == "LX")读出的数据都是正确的了,但是if (strtemp1 == "YC1") 读出的数据还不正确。
大家再帮我看看了。
CString strtemp1, strtemp2, strtemp3;
int m = 0, n = 0, l = 0;
int itemp1 = 0, itemp2 = 0, itemp3 = 0, itemp4 = 0, itemp5 = 0, atrr = 0;
int x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;
BOOL engross = 0;
后面的InitData也对不同数量的参数进行了重载。
不要用strtemp1=="WC"
现在发现一个问题,原来数据文件里面对应"WC"和"YC2"的数据有字符数超过3个的,运行就会出错,一旦把它们删到3个字符长,就可以读取了。这是什么原因哦?
到底怎么回事哦?
哪位知道啊?应该怎么改呢?
谢谢!!