#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; }