📄 subject_28790.htm
字号:
<p>
序号:28790 发表者:chejie 发表日期:2003-01-24 08:30:17
<br>主题:文件操作
<br>内容:假如我要读取一个格式为 test=10 cub=12 inf=8 lin=128 cdac1=128 cdac2=0<BR>的记事本文件,读取10 12 8 128 128 0 <BR>该怎么写代码?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:mm2003 回复日期:2003-01-24 11:03:12
<br>内容:先读取一行,然后做个循环查找‘=’和空格间的字符
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bottle_fish 回复日期:2003-01-24 13:44:12
<br>内容:UP
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:菜鸟也支招儿 回复日期:2003-01-24 15:57:58
<br>内容:我做的比较麻烦,你别见怪!<BR>#include <fstream.h><BR>#include <stdlib.h><BR>#include <string.h><BR>void main()<BR>{ <BR> ifstream inputobject;<BR> inputobject.open("d:\\test.txt");<BR> if(inputobject)<BR> {<BR> cout<<"file has data!"<<endl;<BR> }<BR> char bufFolder[1024],bufNum[10];<BR> memset(bufFolder,0,1024);<BR> inputobject.get(bufFolder,1024,'\0');<BR> int p[10],iNum=0,j1,j2;<BR> for(int i=0;bufFolder[i]!='\0';i++)<BR> {<BR> if(bufFolder[i]=='=')<BR> {<BR> j1=strcspn(&bufFolder[i],"=");<BR> j2=strcspn(&bufFolder[i]," ");<BR> memset(bufNum,0,10);<BR> strncpy(bufNum,&bufFolder[i+1],j2-j1-1); <BR> p[iNum]=atoi(bufNum);<BR> cout<<p[iNum]<<endl;<BR> iNum++;<BR> }<BR> }<BR> inputobject.close();<BR>}<BR>2003-1-24 15:59:56
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -