|
#include <Afx.h> #include <iostream.h>
//以下是读一个文本,将文本中每行以,好分割字符到一个CStringArray ,并读出行中分割数和每个CStringArray int main(int argc, char* argv[]) { CString lu; char kk[35]; cout<<"请输入路径"<<endl; cin>>kk; cout<<endl; lu=kk; CStdioFile file; if(file.Open(lu,CFile::shareDenyNone)) { BOOL isEof=false; CString str; while(!isEof) { isEof=!file.ReadString(str); if(isEof) break; str.TrimLeft(); str.TrimRight(); if(str.Right(1)!=",")str+=","; int pos=-1; int k=0; CString temp; CStringArray array; while((pos=str.Find(",",0))!=-1) { k++; temp=str.Left(pos); if(!temp.IsEmpty()&&temp!="") { array.Add(temp); }else { array.Add(_T(" ")); } str=str.Right(str.GetLength()-pos-1); } cout<<"+++++++++++++++++++"<<k<<endl; for(int i=0;i<k;i++) { cout<<array.GetAt(i)<<endl; } } } return 0; } |