您的位置:首页 > 其它

读取文件,输出单词

2011-10-13 21:50 274 查看
#include <iostream>
#include <string>
using namespace std;

int main()
{
FILE *fd;
fd = fopen("f:\\text.txt","rb");

if(!fd)
{
printf("read file error!");
return 0;
}
printf("read file success!\n");

char buf[10];
char* str;

while(!feof(fd))
{
fscanf(fd,"%s",buf);

cout << buf << endl;
if(!strcmp(buf,"zhouqiang")){
cout << "OK"<< endl;
cout << strlen(buf) << endl;
str = new char[strlen(buf)+1];
strcpy(str,buf);
cout << "str: " << str << endl;
}
}
fclose(fd);

return 1;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐