http://community.csdn.net/Expert/topic/3696/3696777.xml?temp=.8820764
void CJsDlg::OnButton1()
{
double m_a,ma;
CString s=L"\r\n";
CFile afile;
CStdioFile myfile(FilePathName,CFile::modeRead);;
afile.Open("e:\\a.txt",CFile::modeCreate|CFile::modeReadWrite);
CString str,a1,a2;
int i=0;
while(myfile.ReadString(str))
{
str.TrimLeft();
str.TrimRight();
m_a=atof(str); if(m_a>=0&&m_a<=1)
{
if(m_a<=1&&m_a>0.6)
{ma=1;}
if(m_a<=0.6&&m_a<=0.3)
{ma=(m_a-0.3)/0.3;}
if(m_a<0.3&&m_a>=0)
{ma=0;}
a1.Format("%f",ma); afile.Write(a1,a1.GetLength()); afile.Write(s,2);
}
i++;
}
afile.Close();
/////////////////
}
着是我程序的全部
为什么afile.Write(a1,a1.GetLength());输出都是0
void CJsDlg::OnButton1()
{
double m_a,ma;
CString s=L"\r\n";
CFile afile;
CStdioFile myfile(FilePathName,CFile::modeRead);;
afile.Open("e:\\a.txt",CFile::modeCreate|CFile::modeReadWrite);
CString str,a1,a2;
int i=0;
while(myfile.ReadString(str))
{
str.TrimLeft();
str.TrimRight();
m_a=atof(str); if(m_a>=0&&m_a<=1)
{
if(m_a<=1&&m_a>0.6)
{ma=1;}
if(m_a<=0.6&&m_a<=0.3)
{ma=(m_a-0.3)/0.3;}
if(m_a<0.3&&m_a>=0)
{ma=0;}
a1.Format("%f",ma); afile.Write(a1,a1.GetLength()); afile.Write(s,2);
}
i++;
}
afile.Close();
/////////////////
}
着是我程序的全部
为什么afile.Write(a1,a1.GetLength());输出都是0
我帮你看看!注明帖子的URL!
看不懂这句有什么用
应该是:
if(m_a<=0.6&&m_a>=0.3)
看看a1得值是什么,特别是a1的长度
{
double m_a,ma;
CString s=L"\r\n";
CFile afile;
CStdioFile myfile(FilePathName,CFile::modeRead);;
afile.Open("e:\\a.txt",CFile::modeCreate|CFile::modeReadWrite);
CString str,a1,a2;
int i=0;
while(myfile.ReadString(str))
{
str.TrimLeft();
str.TrimRight();
m_a=atof(str); if(m_a>=0&&m_a<=1)
{
if(m_a<=1&&m_a>0.6)
{ma=1;}
if(m_a<=0.6&&m_a<=0.3)
{ma=(m_a-0.3)/0.3;}
if(m_a<0.3&&m_a>=0)
{ma=0;}
a1.Format("%f",ma); afile.Write(a1,a1.GetLength()); afile.Write(s,2);
}
i++;
}
afile.Close();
/////////////////
}
我用你的代码试了一下没问题。
源文件:
0.23
0
0.2
0.4
0.8
0.4
0
0
0
0
0
0
0
0
0.2
0.3
0.2
0.2
0.7
0.9
0
0
0
0
0
0
0
0
0
0.2
0.3
0.5
0.4
0.6
0.6
a.txt:
0.000000
0.000000
0.000000
0.000000
1.000000
1.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
1.000000
1.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000