CString TextPath=”C:\Users\Administrator\Desktop\第0步去噪\configuration.txt”;
FILE *fa = NULL;
fa = fopen(TextPath,”r+”);
CString B = “0”;
CString A1[2] = { 0 };
int i;
for (i = 0; i < 2; i++)
{
fscanf(fa,”%s\n”,B);
A1[i] = B;
}
第一次循环是没有问题的,可以把B的内容赋值给A1[0],第二次循环就出问题了,B不仅把内容赋值给A1[1],还赋值给了A1[0]。问一下是怎么回事~?
FILE *fa = NULL;
fa = fopen(TextPath,”r+”);
CString B = “0”;
CString A1[2] = { 0 };
int i;
for (i = 0; i < 2; i++)
{
fscanf(fa,”%s\n”,B);
A1[i] = B;
}
第一次循环是没有问题的,可以把B的内容赋值给A1[0],第二次循环就出问题了,B不仅把内容赋值给A1[1],还赋值给了A1[0]。问一下是怎么回事~?
解决方案
15
CString用的不对啊
CString A1[2] = { 0 };改为 CString A1[2];
CString A1[2] = { 0 };改为 CString A1[2];
fscanf( fa,"%s\n" , B.GetBuffer(最大长度) ); B.ReleaseBuffer(); A1[i]=B;
25
学会百度“fscanf CString”
http://blog.sina.com.cn/s/blog_609dd92c01018ktm.html
http://blog.sina.com.cn/s/blog_609dd92c01018ktm.html