fileoperation.txt
来自「蚂蚁算法的VC++源程序代码」· 文本 代码 · 共 37 行
TXT
37 行
1.打开文件
char* pFileName = "test.dat";
CStdioFile f1;
if( !f1.Open( pFileName,CFile::modeRead | CFile::typeText ) ) {
#ifdef _DEBUG
afxDump << "Unable to open file" << "\n";
#endif
exit( 1 );
}
2.读文件
char buf[100];
f1.ReadString( buf, 99 );
buf中数据为"1 2 4 6 7"
3.分离元素
int i;
int count=0;
char ch;
char xbuf[100];
memset(xbuf,0,100);
int j = 0;
for( i = 0; i < strlen(buf); i ++ ) {
ch = buf[j++];
xbuf[i]=ch;
if( ch == ' ' ) {
count++;
//此时xbuf中存了一个元素,将其赋给其它变量
memset(xbuf,0,100);
j=0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?