📄 subject_61463.htm
字号:
<p>
序号:61463 发表者:苏少 发表日期:2003-11-19 21:55:52
<br>主题:百思不得其解,请高人指点!
<br>内容:#include<iostream.h><BR>#include<fstream.h><BR>struct token<BR>{<BR> char a;<BR> char b;<BR>};<BR>token array[100];<BR>int i;<BR>void main()<BR>{<BR> ifstream myf("new.txt",ios::nocreate);<BR> if(myf.fail()){cout<<"fail!";return;}<BR> char ch;i=0;<BR> while(!myf.eof())<BR> { h=myf.get();<BR> array[i].a=ch;<BR> array[i].b=ch;<BR> i++;<BR> }cout<<i;<BR> for(int j=0;j<i;j++)<BR> {cout<<array[i].a<<" "<<array[i].b<<endl;}<BR>}<BR>上面是源程序,new.txt的内容是“hello wordl!”,但实际的输出结果是"21",请高人指点!<BR>我的目的是把new.txt的内容存在结构数组中再输出,但是却不能?为什么会这样呢?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:凯凯 回复日期:2003-11-19 22:01:53
<br>内容: for(int j=0;j<i;j++)<BR> {cout<<array[i].a<<" "<<array[i].b<<endl;}<BR><BR>应该为<BR> for(int j=0;j<i;j++)<BR> {cout<<array[j].a<<" "<<array[j].b<<endl;}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -