|
发表于 2004-10-19 08:22:26
|
显示全部楼层
帮你排了一下版
[code:1]
#include <iostream>
#include <string>
#include <tchar.h>
#include <ctype.h>
#include <fstream>
using namespace std;
#ifndef MAX_WORD_LEN
#define MAX_WORD_LEN 20
#endif
TCHAR ch=' ';
bool not_a_character(TCHAR ch)
{
bool bRetCode = true;
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
bRetCode = false;
return bRetCode;
}
typedef enum{ok,fail,end} retType;
retType get_a_word(ifstream& in,TCHAR* result)
{
retType ret = ok;
result[0]='\0';
int index = 0;
while(ch!=EOF&&not_a_character(ch))
{
ch = in.get();
if(ch == EOF)
{
ret = end;
break;
}
}
while(ch!=EOF&&index<=MAX_WORD_LEN&&!not_a_character(ch))
{
result[index]=ch;
ch = in.get();
index++;
}
result[index]='\0';
return ret;
}
int main(int argc,TCHAR* argv[])
{
int iRetCode = 0;
//////
TCHAR buffer[MAX_WORD_LEN+1];
//////
ifstream input;
input.open(_T("c:\\temp\\test.txt"));
if(!input.is_open())
{
iRetCode = 1;
}
else
{
while(get_a_word(input,buffer)!=end)
{
cout<<buffer<<endl;
}
}
return iRetCode;
}
[/code:1] |
|